Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QComboBox inside QTreeWidgetItem

Tags:

qt

qt4

pyqt

pyqt4

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?

like image 530
Piotr Byzia Avatar asked Nov 03 '09 14:11

Piotr Byzia


1 Answers

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:

enter image description here

like image 65
Aaron Digulla Avatar answered Sep 20 '22 11:09

Aaron Digulla