Results 1 to 5 of 5

Thread: QButtonGroup usage?

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QButtonGroup usage?

    I do not understand how useful could QButtonGroup be. It is impossible to add it in a layout, as said in the doc, it is described as a layout tool managing several button so when should we use it rather than QGroupBox? There is no QButtonGroup example in the doc but many QGroupBox ones, would have been better to have a short example per class...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QButtonGroup usage?

    Imagine you are writiting a calculator. Are you going to write separate connect statement and slot for each button?
    Or imagine you want to allow your users to select search criteria using a sets of radio buttons. Are you going to write a set of if-else statements, like:
    Qt Code:
    1. if( _ui.button1->isChecked() ) {
    2. ...
    3. }
    4. else if( _ui.button2->isChecked() ) {
    5. ...
    6. }
    7. ...
    To copy to clipboard, switch view to plain text mode 
    ?

    In both cases QButtonGroup might ease your job.

  3. #3
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QButtonGroup usage?

    Ok but why not using a QGroupBox and a set of RadioButtons in it, as in the doc example?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QButtonGroup usage?

    Quote Originally Posted by Caius Aérobus View Post
    Ok but why not using a QGroupBox and a set of RadioButtons in it, as in the doc example?
    How is QGroupBox going to help you to get rid of if-else statements?

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

    Default Re: QButtonGroup usage?

    Note, that QButtonGroup provides single set of signals for all contained buttons,

    so...
    if you have 100 of buttons
    you'll have 1 connect & 1 slot for all of them with usage of QButtonGroup or
    100 of connects(1 for each button) without it.

    QButtonGroup have nothing to do with visual size of application - it manages the states of buttons so you have to write less code.
    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).

Similar Threads

  1. Reducing CPU Usage
    By Kapil in forum Qt Programming
    Replies: 8
    Last Post: 3rd April 2011, 15:43
  2. QEffects.cpp usage.....
    By Naveen in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2011, 12:07
  3. QPersistentModelIndex usage info request
    By defumar in forum Qt Programming
    Replies: 3
    Last Post: 18th January 2008, 16:40
  4. How to determine memory usage?
    By nopalot in forum General Programming
    Replies: 3
    Last Post: 11th February 2007, 20:50

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.