Hello;
I have a QTreeView using a model subclassing QAbstractItemModel.
I want one of the item (QModelIndex) to be QComboBox?
Thank you for any help.
Mut.
Hello;
I have a QTreeView using a model subclassing QAbstractItemModel.
I want one of the item (QModelIndex) to be QComboBox?
Thank you for any help.
Mut.
Implement a custom delegate that will return a combo box for these items.
If you want a cell editable as a combobox, then you need an item delegate that creates a combobox as the editor for that cell.
See QStyledItemDelegate for an often suitable base class.
Cheers,
_
Thank you for the reply.
This thread http://www.qtcentre.org/threads/4314...x-in-QTreeView shows how to implement a delegate.
However, I'm wondering if "TreeView->setItemDelegateForColumn(8, delegate);" will not put a combobox in all the cells of the column?
What is the API the put the combobox into a specicifc QModelIndex?
I wonder if there is a clean example out there with not only how to create a delegate but also how to use it with QtreeView-QAstractItemModel?
Mut.
QComboBox *cb = new QComboBox;
cb->addItem("a");
treeView->setIndexWidget(currentIndex,cb);
I have used above code and its seems to work. what is the difference between the delegate approach and the setIndexWidget() approach?
setIndexWidget does not bind the widget with the model in any way.
Thanks for the reply.
I'm using signal/slot to connect with the model. It is working fine.
How to delete a combobox that was added with setIndexWidget()?
Use case is: 1) the row holding the combobox is deleted 2) the combobox needs to be relocated to another location due to tree layout change
Bookmarks