Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. buttons to enable if conditions
Forum Updated to NodeBB v4.3 + New Features

buttons to enable if conditions

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 966 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viniltc
    wrote on last edited by
    #1

    Hi all,

    I have two conditions inside a method. I also have two Radio Buttons, buttonOne and buttonTwo.

    My requirement is if I click buttonOne AND the other conditions are true , eventOne is true, else if I click buttonTwo and other conditons are true eventTwo is true

    void 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

    Pl45m4P 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      2
      • V Offline
        V Offline
        viniltc
        wrote on last edited by
        #3

        @mrjj Thank you.
        What confusing me is how to check radiobutton value inside mousePressEvent. Could you show me an example?

        mrjjM 1 Reply Last reply
        0
        • V viniltc

          @mrjj Thank you.
          What confusing me is how to check radiobutton value inside mousePressEvent. Could you show me an example?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @viniltc
          Hi
          Its just
          bool checked = ui->radioButtonName->isChecked();

          But you must click it first then on MainWin

          1 Reply Last reply
          1
          • V viniltc

            Hi all,

            I have two conditions inside a method. I also have two Radio Buttons, buttonOne and buttonTwo.

            My requirement is if I click buttonOne AND the other conditions are true , eventOne is true, else if I click buttonTwo and other conditons are true eventTwo is true

            void 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

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #5

            @viniltc

            Instead of using the MouseClick-event, you can add both of your RadioButtons to a QButtonGroup, connect the QButtonGroup::buttonToggled signal 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;
                    }
                }
            }
            
            

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            4
            • V Offline
              V Offline
              viniltc
              wrote on last edited by
              #6

              Thanks a lot for your feedback @mrjj , @Pl45m4

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved