Problems connecting PushButtons
I im, as you probably will understand, really new to qt.
Im trying to connec a couple of pushbuttons but cant get it to work.
Lets say I have three buttons, now i them with setCheckabel(true), if I click one of the it shuld be checked but when I click another one the that was checked should uncheck and the new one should be checked.
I have tried a couple of diffrent ways but I mostly get the message that slot doesnt exist.
How do I do this?
Re: Problems connecting PushButtons
Have a look at QButtonGroup. It solves your problem.
Re: Problems connecting PushButtons
Thanks!!
Works like a charm : )
1 Attachment(s)
Re: Problems connecting PushButtons
This might be also useful for you (complete app attached):
Code:
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 );
}
}
Note: I don't see QButtonGroup in designer (4.2.0-tp1)