buttons to enable if conditions
-
Hi all,
I have two conditions inside a method. I also have two Radio Buttons,
buttonOneandbuttonTwo.My requirement is if I click
buttonOneAND the other conditions are true ,eventOneis true, else if I clickbuttonTwoand other conditons are trueeventTwois truevoid MainWindow::mousePressEvent(QMouseEvent *event) { QPoint a = event->pos(); if (distance ( a,b) < 20 && ( a.x() > b.x() && a.x() < c.x() )) { eventOne = true; } else if (distance ( a,e) < 20 && ( a.x() > e.x() && a.x() < f.x() )) { eventTwo = true; }How do I implement this?
Thank you
-
Hi
But MainWindow is not involved in clicking on the radio buttons as such.
Radio Buttons has their own signal for that and you connect that to a slot to handle that.
MousePress for MainWindow will not fire when you click on other widgets. Only when you click on MainWindow directly.But in mousePressEvent you can check their values of cause. so if u click first radio and then MainWidnow, you can check it there.
-
@mrjj Thank you.
What confusing me is how to check radiobutton value inside mousePressEvent. Could you show me an example? -
Hi all,
I have two conditions inside a method. I also have two Radio Buttons,
buttonOneandbuttonTwo.My requirement is if I click
buttonOneAND the other conditions are true ,eventOneis true, else if I clickbuttonTwoand other conditons are trueeventTwois truevoid MainWindow::mousePressEvent(QMouseEvent *event) { QPoint a = event->pos(); if (distance ( a,b) < 20 && ( a.x() > b.x() && a.x() < c.x() )) { eventOne = true; } else if (distance ( a,e) < 20 && ( a.x() > e.x() && a.x() < f.x() )) { eventTwo = true; }How do I implement this?
Thank you
Instead of using the MouseClick-event, you can add both of your RadioButtons to a
QButtonGroup, connect theQButtonGroup::buttonToggledsignal to your function (check if your other condition is true) and check which RadioButton was "clicked" / toggled (has the "dot").QButtonGroup *btnGrp = new QButtonGroup(this); btnGrp->addButton(radioBtn_1, 0); btnGrp->addButton(radioBtn_2, 1); void (QButtonGroup::*signal)(int, bool) = &QButtonGroup::buttonToggled; // Send rButton ID and state (true / false) with signal connect(btnGrp, signal, this, &MainWindow::YOUR_SLOT);Your slot could look like this:
void MainWindow::checkCondition(int id, bool checked) { if(checked && condition) // bool condition, if your other condition (calculation thing) is true { switch(id) { case 0: // RadioBtn 1 + Condition = true break; case 1: // RadioBtn 2 + Condition = true break; } } }