Results 1 to 7 of 7

Thread: Radio buttons in a tree view

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Radio buttons in a tree view

    Why not implement QItemDelegate::createEditor() .etc to create a radioButton and open it persistent in treeView?
    imho, it is bad idea, because performance of your application will decrease, because a lot of descendants of QRadioButton are opend. I think the best way is implement your own model/delegate which will allow to use radio-items approach.

  2. #2
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Radio buttons in a tree view

    Quote Originally Posted by spirit View Post
    imho, it is bad idea, because performance of your application will decrease, because a lot of descendants of QRadioButton are opend. I think the best way is implement your own model/delegate which will allow to use radio-items approach.
    thank you. so, as "Delegate Class" part in Qt's doc says, "Delegates are expected to be able to render their contents themselves by implementing the paint() and sizeHint() functions.", it is not expected to keep a real editor widget persistently? if i need a radio button in some cells all the time, what should i do? should i implement CustomDelegate:aint(), and paint pixmaps of radio_on and radio_off in the cells? I used to do this like this:

    CustomDelegate::createEditor()
    {
    return new QRadioButton;
    }

    and calling QItemView:penPersistentEditor()for each index, or else the editor will be destroyed the editing finishes. i knew it's not a good way i really need a radiobutton in my view.

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Radio buttons in a tree view

    1) (quick method) you can use add method setExclusive to a view or to a delegate and then reimplement this method QItemDelegate::drawCheck. according to exclusivity you can draw checkbox (just call drawCheck of paren, i.e. QItemDelegate::drawCheck) or radiobox.
    2) subclass a needed model, then subclass a needed item, e.g. QStandartItem, add to it mehtod setExclusive and extend methods setChecked for supporting exclusivity () and then reimplement a method QItemDelegate::drawCheck.
    I think that's all. I hope, I helped you.
    Last edited by spirit; 3rd November 2008 at 07:39.

  4. The following user says thank you to spirit for this useful post:

    nifei (3rd November 2008)

  5. #4
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Radio buttons in a tree view

    Quote Originally Posted by spirit View Post
    1) (quick method) you can use add method setExclusive to a view or to a delegate and then reimplement this method QItemDelegate::drawCheck. according to exclusivity you can draw checkbox (just call drawCheck of paren, i.e. QItemDelegate::drawCheck) or radiobox.
    2) subclass a needed model, then subclass a needed item, e.g. QStandartItem, add to it mehtod setExclusive and extend methods setChecked for supporting exclusivity () and then reimplement a method QItemDelegate::drawCheck.
    I think that's all. I hope, I helped you.
    thanks a lot. i'll try.

Similar Threads

  1. Programatically setting radio buttons
    By Doug Broadwell in forum Newbie
    Replies: 2
    Last Post: 25th May 2007, 20:55
  2. Ignore mouse events out of tree view
    By krishna.bv in forum Qt Programming
    Replies: 3
    Last Post: 27th December 2006, 11:24
  3. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50
  4. array of radio buttons
    By amulya in forum Qt Programming
    Replies: 4
    Last Post: 5th October 2006, 12:59
  5. How to get larger radio buttons on XP?
    By Ben.Hines in forum Qt Programming
    Replies: 9
    Last Post: 24th April 2006, 19:00

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
  •  
Qt is a trademark of The Qt Company.