[PyQt] How can I add a QBomboBox to a QTreeView?

Baz Walter bazwal at ftml.net
Sat Apr 5 19:54:27 BST 2014


On 05/04/14 13:17, Martin B. wrote:
> I've created a QTreeView and a QStandardItemModel.
> Then I add several rows and replace the item in the second column with a
> combobox.
>
> item = QStandardItem(text2)
> model.appendRow([ QStandardItem(text1), item ])
>
> cbx = QComboBox()
> cbx.addItem("A")
> cbx.addItem("B")
>
> tvw.setIndexWidget(model.indexFromItem(item), cbx)
>
> The problem is that the combobox doesn't show up. Instead text2 is shown.
>
> What is wrong with this code?

Nothing. I would guess that you did not set the model on the treeview 
before adding the items.

-- 
Regards
Baz Walter


More information about the PyQt mailing list