QButtonGroup in QBoxLayout
-
thanky. If you have three RadioButton how do you chck wich one is currently checked?
-
[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.
-
yes of course. But I have to check every RadioButton. The QButtonGroup has a signal that takes as formal paramter QAbstractButton (the button you clicked)
-
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())
{
// * * *
}
}
@ -
what is "this"? Every RadioButto?
-
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.-
-
so QGroupBox would receive the same buttonClicked(QAbstractButton*) signal of QGroupButton?
Thank you
-
Actually, I was wrong on QGroupBox. Though it will make QRadioButton's behave exclusively between the ones inside the group box, it does not provide the signalling QButtonGroup provides. My apologies.
-
Nerver mind. So cominng back to the original question:
Is it possible to a QButtonGroup in a QBoxLayout? If yes, how?
Thank you
-
No, because QButtonGroup is not a widget. However, you can add the radio buttons to the box layout, and still add those radio buttons to a QButtonGroup.