QTreeWidgetItem 内的 QComboBox [英] QComboBox inside QTreeWidgetItem
本文介绍了QTreeWidgetItem 内的 QComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有类似于(PyQT)的东西QTreeWidgetItem.setCheckState(0, Qt.Checked)
但是对于组合框?
我在参考中看不到任何内容,那么如何插入自定义 QComboBox 作为 QTreeWidgetItem 中的元素之一?
解决方案
使用
Is there something similar to the (PyQT)
QTreeWidgetItem.setCheckState(0, Qt.Checked)
but for the combo box?
I can't see anything in the reference, so how can I insert a custom QComboBox as one of the elements within QTreeWidgetItem?
解决方案
Use QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget ) to put the combo box into the cells.
For example, let's make all rows of the second column of a 2-column QTreeWidget to all be combo boxes:
QTreeWidgetItemIterator it(ui->treeWidget);
while (*it) {
QComboBox *comboBox = new QComboBox(this);
comboBox->addItems(QStringList() << "item1" << "item2");
ui->treeWidget->setItemWidget(*it, 1, comboBox);
++it;
}
Our example widget now looks like this:
这篇关于QTreeWidgetItem 内的 QComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文