1
目前我有这样的代码到几QLineEdits添加到ui.widget
,但我还需要一个垂直滚动条元素过多的情况下 - >可用的空间有限:使用滚动条与QGridLayout
QGridLayout *gridLayout = new QGridLayout(ui.widget);
int rowIndex = 0, colIndex = 0;
for(auto number : m_numbers)
{
QLineEdit *lineEdit = new QLineEdit();
gridLayout->addWidget(lineEdit, rowIndex, colIndex, Qt::AlignLeft);
if(colIndex == 7)
{
colIndex = 0;
++rowIndex;
}
else ++colIndex;
}
ui.widget->setLayout(gridLayout);
我怎样才能使滚动?
您是否有基于我的代码的完整示例? Thx – leon22
我认为QScrollArea对你有好处,为什么不呢?而QScrollBar也可以完成这项工作。 – aghilpro
我试图改变它,但不起作用!在ui.widget-> setLayout(gridLayout);之后我添加了QScrollArea * scrollArea = new QScrollArea; scrollArea-> setWidget(ui.widget); - >它没有元素是空的。 – leon22