Hi,
I have created a ui file using Qt Designer, and here I've placed three qpushbuttons in a QGroupBox in one QGridLayout, and in another QGroupBox I've created three other QPushButtons.
Inside GroupBox 1 the three qpushbuttons (pb1,pb2,pb3) are put in a vertical layout.
Inside GroupBox 2 the other three qpushbuttons (pb4,pb5,pb6) are put in e.g qgridlayout
pb1 and pb5 is active (setDown(true)) at initialization.
So far so good.
Intention on how it should work. Only one qpushbutton in a groupbox should be active (isDown() = true).
So when I e.g click pb2, then pb2 is the only active pushbutton i groupbox1 that should be active. Leaving pushbuttons in Groupbox 2 as they are.
But when I click pb2, I get strange behaviour. Clicking pb2 could give the following outcomes:
* Cancels the active pb1, and setDown(true) on itself. => Correct
* Cancels the active pb1, and setDown(true) on itself and on pb3.
* Cancels the active pb1, and one of the above situations occur, but turning on and off pushbuttons on GroupBox2. Really not wanted.
I've tried to counteract the misbehaviour inside the slot code as below:
if (!v)
return;
if (sender == ui.pb1)
{
sender->setDown(v);
sender->setChecked(true);
ui.pb2->setDown(!v);
ui.pb3->setDown(!v);
}
else if (sender == ui.pb2)
{
sender->setDown(v);
ui.pb1->setDown(!v);
ui.pb3->setDown(!v);
}
else if (sender == ui.pb3)
{
sender->setDown(v);
ui.pb1->setDown(!v);
ui.pb2->setDown(!v);
}
}
QPushButton* sender = dynamic_cast<QPushButton*>(QObject::sender());
if (!v)
return;
if (sender == ui.pb1)
{
sender->setDown(v);
sender->setChecked(true);
ui.pb2->setDown(!v);
ui.pb3->setDown(!v);
}
else if (sender == ui.pb2)
{
sender->setDown(v);
ui.pb1->setDown(!v);
ui.pb3->setDown(!v);
}
else if (sender == ui.pb3)
{
sender->setDown(v);
ui.pb1->setDown(!v);
ui.pb2->setDown(!v);
}
}
To copy to clipboard, switch view to plain text mode
But with no luck, it still change states of pushbuttons in the other groupbox.
How can I stop the pushbuttons in one groupbox to influence other pushbuttons in the other groupboxes?
I've tried to remorph GroupBoxes into QWidget, QFrame....but the problem are still there.
Bookmarks