QButtonGroup in QBoxLayout
-
[quote author="blackbelt" date="1342710428"]thanky. If you have three RadioButton how do you chck wich one is currently checked?[/quote]
Just follow the documentation :)
bq. Use "isChecked()":http://qt-project.org/doc/qt-4.8/qabstractbutton.html#checked-prop to see if a particular button is selected.
-
Declare a slot that is called when one of buttons in QButtonGroup is clicked.
@
public slots:void buttonClicked(QAbstractButton* button);
@Bind the signal and the slot
@
connect(this , SIGNAL(buttonClicked(QAbstractButton*)),this,SLOT(buttonClick(QAbstractButton*)));
@Detect the button based on it's text.
@
void MyClass::buttonClicked(QAbstractButton* button);
{
if ("radio button text" == button->text())
{
// * * *
}
}
@ -
I'd go for the [[doc:QButtonGroup]] solution.
You can add the buttons to a group from within designer.Simply add the radio buttons to your form. Select them all, and right click on any of them. Choose Add to Buttongroup -> New buttongroup. Nothing obvious will change, but in your Object Inspector pane you'll notice a new QButtonGroup object. Select it to change the name to something sensible.
Now, you can simply connect to the button groups' signals. If you need more control of the ID's of each of the group member, you'll need to do the construction of the button group and the adding of the radio buttons in code. I'd do that once in your constructor. After that, you can use its signals again.
-Note that a QGroupBox also works as a QButtonGroup.-