+ Reply to Thread
Results 1 to 6 of 6

Thread: QTreeWidgetItem + radio Button

  1. #1
    Join Date
    Jul 2006
    Posts
    37
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Cool QTreeWidgetItem + radio Button

    Hi Guys,

    Do you know a way to make QtreeWidgetItem with radio button inside instead of checkboxes?

    Thanks,

    David

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,317
    Thanks
    3
    Thanked 5,000 Times in 4,780 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QTreeWidgetItem + radio Button

    Do you want those buttons to be mutually exclusive?

  3. #3
    Join Date
    Jul 2006
    Posts
    37
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTreeWidgetItem + radio Button

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,317
    Thanks
    3
    Thanked 5,000 Times in 4,780 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QTreeWidgetItem + radio Button

    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.

  5. The following user says thank you to wysota for this useful post:

    Cupidvogel (3rd March 2016)

  6. #5
    Join Date
    Jul 2006
    Posts
    37
    Thanks
    6
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTreeWidgetItem + radio Button

    OK,

    Thanks for your quick reply

  7. #6
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeWidgetItem + radio Button

    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).

+ Reply to Thread

Similar Threads

  1. Undoing radio button checks.
    By Doug Broadwell in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2007, 10:12
  2. array of radio buttons
    By amulya in forum Qt Programming
    Replies: 4
    Last Post: 5th October 2006, 13:59
  3. Paint XP radio button to pixmap
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2006, 22:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts