带有滚动区域和网格布局的 qdialog
我有一个 QDialog,其中我想在 10 x 5 网格中显示 50 个 QComboBox。由于这么多组合框不适合我的对话框,我想使用滚动。
这是我尝试过的,但这对我不起作用。我的这个解决方案是否朝着正确的方向前进?
// setup scroll area
QScrollArea *scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(true);
// setup grid layout
QRect rect;
rect.setX(0);
rect.setY(0);
rect.setWidth(1920);
rect.setHeight(1080);
QGridLayout *gridLayout = new QGridLayout;
gridLayout->setGeometry(rect);
// add servers to scroll area
QComboBox *cmbxServer;
int row = 0;
int col = 0;
for (col = 0; col < 10; col++)
{
gridLayout->setColumnMinimumWidth(col, 150);
gridLayout->setColumnStretch(col, 0);
}
for (row = 0; row < 5; row++)
{
for (col = 0; col < 10; col++)
{
cmbxServer = new QComboBox(this);
cmbxServer->setGeometry(0, 0, 150, 30);
cmbxServer->addItem("Item 1");
cmbxServer->addItem("Item 2");
cmbxServer->addItem("Item 3");
gridLayout->addWidget(cmbxServer, row, col);
}
}
gridLayout->addWidget(scrollArea);
感谢所有帮助 多蒂瓦拉
I have a QDialog inside which I want to display 50 QComboBoxes in a 10 x 5 grid. Since so many combo boxes will not fit into my dialog box, I want to use scrolling.
Here is what I've tried, but this does not work for me. Am I even headed in the right direction with this solution?
// setup scroll area
QScrollArea *scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(true);
// setup grid layout
QRect rect;
rect.setX(0);
rect.setY(0);
rect.setWidth(1920);
rect.setHeight(1080);
QGridLayout *gridLayout = new QGridLayout;
gridLayout->setGeometry(rect);
// add servers to scroll area
QComboBox *cmbxServer;
int row = 0;
int col = 0;
for (col = 0; col < 10; col++)
{
gridLayout->setColumnMinimumWidth(col, 150);
gridLayout->setColumnStretch(col, 0);
}
for (row = 0; row < 5; row++)
{
for (col = 0; col < 10; col++)
{
cmbxServer = new QComboBox(this);
cmbxServer->setGeometry(0, 0, 150, 30);
cmbxServer->addItem("Item 1");
cmbxServer->addItem("Item 2");
cmbxServer->addItem("Item 3");
gridLayout->addWidget(cmbxServer, row, col);
}
}
gridLayout->addWidget(scrollArea);
thanks for all help
Dhotiwalla
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您正朝着正确的方向前进。做如下的事情
Yes you are heading in right direction. Do something as below