PDA

View Full Version : QButtonGroup usage?



Caius Aérobus
21st April 2008, 21:34
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...

jacek
21st April 2008, 22:00
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:

if( _ui.button1->isChecked() ) {
...
}
else if( _ui.button2->isChecked() ) {
...
}
...?

In both cases QButtonGroup might ease your job.

Caius Aérobus
21st April 2008, 22:13
Ok but why not using a QGroupBox and a set of RadioButtons in it, as in the doc example?

jacek
22nd April 2008, 00:30
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?

mchara
22nd April 2008, 07:38
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.