This might be also useful for you (complete app attached):
myApp::myApp()
{
setupUi(this);
int count;
count = splitter->count(); // number of buttons in splitter
// splitter is filled with buttons in designer
// connect them all
for(int i=0;i<count;i++)
{
widget = splitter->widget(i);
connect( button, SIGNAL( toggled(bool) ), this, SLOT( checkUncheck() ) );
}
}
void myApp::checkUncheck() // slot
{
int count, index;
count = splitter->count();
obj = sender();
button = qobject_cast<QPushButton *>(obj);
index = splitter->indexOf(button);
// if state not checked - return (we just unchecked button)
if (button->isChecked() == false) return;
for(int i=0;i<count;i++)
{
if ( i == index ) continue; // we skip current button
widget = splitter->widget(i);
if (tmpButton->isChecked() == true) tmpButton->setChecked ( false );
}
}
myApp::myApp()
{
setupUi(this);
int count;
QWidget *widget;
QPushButton *button;
count = splitter->count(); // number of buttons in splitter
// splitter is filled with buttons in designer
// connect them all
for(int i=0;i<count;i++)
{
widget = splitter->widget(i);
button = (QPushButton*) widget;
connect( button, SIGNAL( toggled(bool) ), this, SLOT( checkUncheck() ) );
}
}
void myApp::checkUncheck() // slot
{
int count, index;
QObject *obj;
QPushButton *button, *tmpButton;
QWidget *widget;
count = splitter->count();
obj = sender();
button = qobject_cast<QPushButton *>(obj);
index = splitter->indexOf(button);
// if state not checked - return (we just unchecked button)
if (button->isChecked() == false) return;
for(int i=0;i<count;i++)
{
if ( i == index ) continue; // we skip current button
widget = splitter->widget(i);
tmpButton = (QPushButton*) widget;
if (tmpButton->isChecked() == true) tmpButton->setChecked ( false );
}
}
To copy to clipboard, switch view to plain text mode
Note: I don't see QButtonGroup in designer (4.2.0-tp1)
Bookmarks