gpt4 book ai didi

c++ - QTableWidget - setCellWidget 缺少添加?

转载 作者:行者123 更新时间:2023-11-28 08:08:24 25 4
gpt4 key购买 nike

我只是想将小部件添加到我的表格小部件中,我正在尝试下面的代码,但在我运行程序的所有时间里,第一个小部件被添加但其余的没有添加。你能帮我解决这种情况吗?

if(req.at(index).request.CodedValue.size() > 1 )
{
int rowNumber = -1;
for ( int paramNumber = 0 ; paramNumber < req.at(index).request.params.size(); paramNumber++)
{

if(req[index].request.params[paramNumber].semantic == "DATA")
{
rowNumber++;
QComboBox* reqComboBox = new QComboBox();
QLineEdit* tableReqLineEdit = new QLineEdit();

for ( int codedCounter = 0; codedCounter < req.at(index).request.CodedValue.at(paramNumber).trams.size(); codedCounter++)
{
// you should look for the subfunctions and add according to them
reqComboBox->addItem((req[index].request.CodedValue[paramNumber].trams[codedCounter].valueName));
QObject::connect(reqComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_tableCombobox_currentIndex());
}
ui.tableWidget->setCellWidget(rowNumber,1,reqComboBox);

}
}
}

最佳答案

使用qDebug为了查看 for 循环执行了多少次。大概只执行一次:

#include <QDebug>
...
rowNumber++;
qDebug() << rowNumber;
...

尝试以下操作:

for (int i=0; i<ui.tableWidget->rowCount(); i++)
{
ui.tableWidget->setCellWidget(i,1,new QLineEdit);
}

您看到多少行编辑?

请注意,您应该使用 setRowCount 来设置表格小部件的行数。

关于c++ - QTableWidget - setCellWidget 缺少添加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9717221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com