PDA

View Full Version : How to dinamically change the type of a QCheckListItem



kalos80
12th March 2007, 11:25
I have a list view made up by check list items.

The type of parent list view items is CheckBoxController while the type of leaves items is CheckBox (this distinction is needed in order to properly manage the tristate of the QCheckListItem).

The user can delete all children of an item, in such case I have to change the type of such item from CheckBoxController to CheckBox otherwise the tristate is wrongly managed.

Is there a way to easily change the type of a QCheckListItem at run time?

Thanks a lot for your help.

wysota
12th March 2007, 12:36
You'll have to create a new object of a proper class.

kalos80
12th March 2007, 12:57
Can you be more specific?

I already have a class derived from the QCheckListItem but the QCheckListItem is not providing any way to change the type of the QCheckListItem. The only way to specify the type is to pass it in the constructor, but I need to change the type after the object has been created.

wysota
12th March 2007, 14:28
I mean you have to create a "CheckBox" instance and replace the "CheckBoxController" instance with it. You can't change the class of an already existing object. Of course you can make the "Controller" class a subclass of the "CheckBox" class and extend it to provide additional functionality, which could just be "downgraded" when the item has no children.

kalos80
12th March 2007, 15:25
Wysota thank you very much for your hints, I'm gonna implement them.