Hi Guys,
Do you know a way to make QtreeWidgetItem with radio button inside instead of checkboxes?
Thanks,
David
Hi Guys,
Do you know a way to make QtreeWidgetItem with radio button inside instead of checkboxes?
Thanks,
David
Do you want those buttons to be mutually exclusive?
Yes ; that's it and Radio Button is exactly done for that; but can't set it in QTreeWidgetItem
So thanks for your help
Dzienkuje
David
I know what radio buttons are for Ok, you have to implement the feature yourself. First thing is to provide a delegate to draw the radio button instead of a checkbox - you can do that by reimplementing drawCheck in QItemDelegate. Next you have to make sure that only one item is checked at a time. To do that you need to connect to the models dataChanged() signal and look for changes in the check state. If you notice that an item gets checked, you need to uncheck all others. It'd be easier to do with the model-view approach and a custom model, but if you need that for QTreeWidget, you'll need to write a bit more complex code.
Cupidvogel (3rd March 2016)
OK,
Thanks for your quick reply
Hi,
Another approach is QTreeWidget->setItemWidget(), if you don't want to deal with itemDelegates, that are rather meant for view-model aproach, however you still have to make sure that only one item is checked, as wysota said, except you would have to connect QRadioButton's signals instead of dataModels one.
You can provide i.e. QMap<QTreeWidgetItem*, QRadioButton*>, QList<QRadioButton*> or something similar filled on setItemWidget calls to know what you'll need to uncheck.
sender() method can be usefull to determine which radioButton should remain checked.
See GrEEn (Graphics Effects Environment)
http://sourceforge.net/project/platf...roup_id=232746
a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).
Bookmarks