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. Pushbutton crashed.
QtWS25 Last Chance

Pushbutton crashed.

Scheduled Pinned Locked Moved Solved General and Desktop
c++ qt
26 Posts 5 Posters 3.9k Views
  • 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.
  • G Gutks
    19 Aug 2020, 12:11

    @JonB
    Okay, thanks for trying to help. I will search for a solution to my problem.

    J Offline
    J Offline
    JonB
    wrote on 19 Aug 2020, 12:21 last edited by
    #16

    @Gutks
    Both @Pl45m4 & I are trying to say you don't need to go down the route you are on....

    1 Reply Last reply
    1
    • G Gutks
      19 Aug 2020, 12:11

      @JonB
      Okay, thanks for trying to help. I will search for a solution to my problem.

      P Offline
      P Offline
      Pablo J. Rogina
      wrote on 19 Aug 2020, 12:42 last edited by
      #17

      @Gutks said in Pushbutton crashed.:

      if(p->button()==Qt::LeftButton){ui->lineEdit1->setText(QString::number(value1++));}
      
      else{if(p->button()==Qt::RightButton){ui->lineEdit1->setText(QString::number(value1--));}
      

      From your requirements it's apparent you need a custom QPushButton that extends existing one by adding just the rightclicked() signal, and nothing else. So you'll have both signals (existing left click) and new one (right click) to connect as you wish.

      Please take a look at this SO question & answers.

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • G Gutks
        19 Aug 2020, 12:11

        @JonB
        Okay, thanks for trying to help. I will search for a solution to my problem.

        J Offline
        J Offline
        JonB
        wrote on 19 Aug 2020, 12:45 last edited by JonB
        #18

        @Gutks
        If what @Pablo-J-Rogina has discerned is correct --- you just want a left-/right-click to increment/decrement a number in a QLineEdit, is that right? --- then you would be better just using a QSpinBox, which is for entering numbers, and you wouldn't have any of this.....

        P 1 Reply Last reply 19 Aug 2020, 12:48
        1
        • J JonB
          19 Aug 2020, 12:45

          @Gutks
          If what @Pablo-J-Rogina has discerned is correct --- you just want a left-/right-click to increment/decrement a number in a QLineEdit, is that right? --- then you would be better just using a QSpinBox, which is for entering numbers, and you wouldn't have any of this.....

          P Offline
          P Offline
          Pablo J. Rogina
          wrote on 19 Aug 2020, 12:48 last edited by
          #19

          @JonB said in Pushbutton crashed.:

          then you would be better just using a QSpinBox,

          I think the goal here is the rightclicked() signal, what you connect that to is not relevant at this point

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          J 1 Reply Last reply 19 Aug 2020, 12:49
          3
          • P Pablo J. Rogina
            19 Aug 2020, 12:48

            @JonB said in Pushbutton crashed.:

            then you would be better just using a QSpinBox,

            I think the goal here is the rightclicked() signal, what you connect that to is not relevant at this point

            J Offline
            J Offline
            JonB
            wrote on 19 Aug 2020, 12:49 last edited by JonB
            #20

            @Pablo-J-Rogina
            Oh, I see. You may be right. Or it just might turn out the user was going to use a left-/-right-click on a button to inc/dec a number, you never know... :)

            On a different tone, it's "unusual" to have the user right-click on a button. Possible, but possibly not intuitive. A "rocker" pushbutton (click at left/right for different behaviour, but with left mouse) might be another possibility.

            P 1 Reply Last reply 19 Aug 2020, 13:28
            1
            • G Gutks
              19 Aug 2020, 12:11

              @JonB
              Okay, thanks for trying to help. I will search for a solution to my problem.

              P Offline
              P Offline
              Pl45m4
              wrote on 19 Aug 2020, 13:07 last edited by Pl45m4
              #21

              @Gutks

              Button.h

              #ifndef LR_CLICKBUTTON_H
              #define LR_CLICKBUTTON_H
              
              #include <QPushButton>
              
              class LR_ClickButton: public QPushButton
              {
                  Q_OBJECT
              public:
              
                  LR_ClickButton(QWidget *parent = nullptr);
              
              
              protected:
                 void	mousePressEvent(QMouseEvent *e) override;
                 void mouseReleaseEvent(QMouseEvent *e) override;
              
              signals:
                  // Not needed, since one signal which sends MouseEvent to get handled in slot
                  //void leftClicked();
                  //void rightClicked();
              
                  void myClicked(QMouseEvent *e);
              };
              
              #endif // LR_CLICKBUTTON_H
              

              Button.cpp

              #include "lr_clickbutton.h"
              #include <QMouseEvent>
              #include <QDebug>
              LR_ClickButton::LR_ClickButton(QWidget *parent):
                  QPushButton(parent)
              {
              
              }
              
              void LR_ClickButton::mousePressEvent(QMouseEvent *e)
              {
                  QPushButton::mousePressEvent(e);
              }
              
              void LR_ClickButton::mouseReleaseEvent(QMouseEvent *e)
              {
                  if(e->button() == Qt::LeftButton)
                  {
                      qDebug() << "Left";
                      emit myClicked(e);
                  }
                  else if (e->button() == Qt::RightButton) {
              
                      qDebug() << "Right";
                      emit myClicked(e);
              
                  }
                      QPushButton::mouseReleaseEvent(e);
              }
              

              MainWindow.h

              public slots:
                  void myButtonClicked(QMouseEvent *e);
              

              MainWindow.cpp

              // #########  C'TOR  #####################
                  LR_ClickButton *button1 = new LR_ClickButton(this);
              
                  centralWidget()->layout()->addWidget(button1);
              
                  connect(button1, &LR_ClickButton::myClicked, this, &MainWindow::myButtonClicked);
              
              // ######################################
              
              
              void MainWindow::myButtonClicked(QMouseEvent *e)
              {
                  if(e->button() == Qt::LeftButton)
                  {
                      // Of course you can put anything you want here
                      int val = ui->spinBox->value();
                      ui->spinBox->setValue(val + 1);
                  }
                  else if (e->button() == Qt::RightButton) {
              
                      // or here
                      int val = ui->spinBox->value();
                      ui->spinBox->setValue(val - 1);
                  }
              }
              
              
              

              Wasn't that hard, right? :)

              Result:

              3 left-clicks increase value by 3.
              Bildschirmfoto vom 2020-08-19 15-13-02.png

              2 right-clicks decrease value by 2 again.
              Bildschirmfoto vom 2020-08-19 15-13-33.png


              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
              1
              • J JonB
                19 Aug 2020, 12:49

                @Pablo-J-Rogina
                Oh, I see. You may be right. Or it just might turn out the user was going to use a left-/-right-click on a button to inc/dec a number, you never know... :)

                On a different tone, it's "unusual" to have the user right-click on a button. Possible, but possibly not intuitive. A "rocker" pushbutton (click at left/right for different behaviour, but with left mouse) might be another possibility.

                P Offline
                P Offline
                Pl45m4
                wrote on 19 Aug 2020, 13:28 last edited by
                #22

                @JonB said in Pushbutton crashed.:

                On a different tone, it's "unusual" to have the user right-click on a button. Possible, but possibly not intuitive

                Might not be the most intuitive solution but this is actually used a lot in games (with a hint to this behavior ofc)


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

                ~E. W. Dijkstra

                J 1 Reply Last reply 19 Aug 2020, 14:12
                1
                • P Pl45m4
                  19 Aug 2020, 13:28

                  @JonB said in Pushbutton crashed.:

                  On a different tone, it's "unusual" to have the user right-click on a button. Possible, but possibly not intuitive

                  Might not be the most intuitive solution but this is actually used a lot in games (with a hint to this behavior ofc)

                  J Offline
                  J Offline
                  JonB
                  wrote on 19 Aug 2020, 14:12 last edited by
                  #23

                  @Pl45m4
                  Point taken! Not in any of the games I play that I can think of, though most of mine are 2D turn-based from the last millennium... ;-)

                  1 Reply Last reply
                  2
                  • G Offline
                    G Offline
                    Gutks
                    wrote on 19 Aug 2020, 14:38 last edited by Gutks
                    #24

                    @Christian-Ehrlicher @Pl45m4 @JonB @Pablo-J-Rogina

                    Thank you very much, you don't know how it helped me. Otherwise, I would have to create an internal storage system for each button between the tabs and remove it when editing the line.

                    Yes, and a tool I am creating to help the 1 game community. How does it activate as resolved?
                    Captura de tela de 2020-08-19 08-05-11.png

                    J 1 Reply Last reply 19 Aug 2020, 14:40
                    1
                    • G Gutks
                      19 Aug 2020, 14:38

                      @Christian-Ehrlicher @Pl45m4 @JonB @Pablo-J-Rogina

                      Thank you very much, you don't know how it helped me. Otherwise, I would have to create an internal storage system for each button between the tabs and remove it when editing the line.

                      Yes, and a tool I am creating to help the 1 game community. How does it activate as resolved?
                      Captura de tela de 2020-08-19 08-05-11.png

                      J Offline
                      J Offline
                      JonB
                      wrote on 19 Aug 2020, 14:40 last edited by
                      #25

                      @Gutks said in Pushbutton crashed.:

                      How does it activate as resolved

                      Either at bottom of page Topic Tools button, or if you feel a particular post answered it the vertical ... button at the right on that post.

                      P 1 Reply Last reply 19 Aug 2020, 14:44
                      2
                      • J JonB
                        19 Aug 2020, 14:40

                        @Gutks said in Pushbutton crashed.:

                        How does it activate as resolved

                        Either at bottom of page Topic Tools button, or if you feel a particular post answered it the vertical ... button at the right on that post.

                        P Offline
                        P Offline
                        Pl45m4
                        wrote on 19 Aug 2020, 14:44 last edited by
                        #26

                        @JonB

                        This is exactly what I was expecting and what I thought of.... These type of games, where you have ingame shops and a lot of inventories... If you left-click an item, you probably buy it from shop or use it, if you right-click, you drop it or sell it :)


                        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
                        1

                        25/26

                        19 Aug 2020, 14:40

                        • Login

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