View Full Version : Problems connecting PushButtons
Randulf
23rd August 2006, 13:17
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?
jpn
23rd August 2006, 13:56
Have a look at QButtonGroup. It solves your problem.
Randulf
23rd August 2006, 14:36
Thanks!!
Works like a charm : )
sector
23rd August 2006, 14:39
This might be also useful for you (complete app attached):
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 );
}
}
Note: I don't see QButtonGroup in designer (4.2.0-tp1)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.