Unsolved What could be the reason Combo box is not rendering properly in Qtreeview?
-
I am try to set the Qpushbutton and Qcombobox in Qtreeview using setindexwidget. widget is not render properly while showing on table.
it is not generate more frequently.
In image You can see the last 3 combo box are shrink and and start button draw early.
I am not able to regenerate more frequently above bug. actual it should be like below pic.
Here the code for my custom widget.
#include "CustomButton.h" #include "qlayout.h" #include "qpainter.h" CustomButton::CustomButton(int indexOftestgroup, bool _isVoltagTestCases, QWidget* parent) : index(indexOftestgroup) , isVoltagTestCases(_isVoltagTestCases) { this->setParent(parent); auto Hlay = new QHBoxLayout(this); Hlay->setMargin(0); Hlay->setSpacing(0); Hlay->addWidget(pbt = new QPushButton("Start Testing")); connect(pbt, &QPushButton::clicked, [=]() { emit Clicked(index, isVoltagTestCases); // for positive test cases emit Clicked(index+1, isVoltagTestCases); // for negative test cases }); }
CustomComboBox::CustomComboBox(int indexOftestgroup, int indexOfTestCase, bool _isVoltagTestCases, QWidget* parent, TypeOfTestDevice defaultDevice) : index(indexOftestgroup) , isVoltagTestCases(_isVoltagTestCases) , testCaseIndex(indexOfTestCase) { this->setParent(parent); auto Hlay = new QHBoxLayout(this); Hlay->setMargin(0); Hlay->setSpacing(0); Hlay->addWidget(comboBox = new QComboBox(this)); comboBox->addItem(CustomComboBoxText::*****, QVariant::fromValue<TypeOfTestDevice>(TypeOfTestDevice::*****)); comboBox->addItem(CustomComboBoxText::*****, QVariant::fromValue<TypeOfTestDevice>(TypeOfTestDevice::*****)); comboBox->addItem(CustomComboBoxText::*****, QVariant::fromValue<TypeOfTestDevice>(TypeOfTestDevice::*****)); auto currentText = "abc"; comboBox->setCurrentText(currentText); connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int device) { emit selecteNewDevice(index, testCaseIndex, device, isVoltagTestCases); // for positive test cases }); }
set widget in treeview
auto item = new QStandardItem(); auto startTestingBtnRow = instItem->rowCount(); item->setData(index/2, Qt::UserRole); //Save group index item->setData(startTestingBtnRow + 1, Qt::UserRole + 1); instItem->setChild(startTestingBtnRow, TEST_TABLE_COl::START_TESTING_BUTTON_OR_CHECKBOX, item); auto wdg = new CustomButton(index,false, treeWidget); QObject::connect(wdg, &CustomButton::Clicked, mainWindow, &SquidstatQualityTester::TestCaseGroup); auto indexOfwgd = instItem->child(startTestingBtnRow, TEST_TABLE_COl::START_TESTING_BUTTON_OR_CHECKBOX)->index(); treeWidget->setIndexWidget(indexOfwgd, wdg);
{ item = new QStandardItem(); instItem->setChild(row, TEST_TABLE_COl::TEST_DEVICE_SELECT, item); auto wdg = new CustomComboBox(index, subindex, false, treeWidget, tesCaseInputVal.getTypeOfDeviceUsed()); // group Index, TestCase Index, Not Volatge, Parent Widget. QObject::connect(wdg, &CustomComboBox::selecteNewDevice, [=](int groupIndex, int testCaseIndex, int value, bool isVoltageGroup) { mainWindow->EditModelValue(groupIndex, testCaseIndex, value, TEST_TABLE_COl::TEST_DEVICE_SELECT, isVoltageGroup); }); auto indexOfwgd = instItem->child(row, TEST_TABLE_COl::TEST_DEVICE_SELECT)->index(); treeWidget->setIndexWidget(indexOfwgd, wdg); }
any suggestion or direction what could be the reason that sometime customwidget are not set properly in QTreeview?