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. ui detect mouse event on objects
Forum Updated to NodeBB v4.3 + New Features

ui detect mouse event on objects

Scheduled Pinned Locked Moved Unsolved General and Desktop
26 Posts 6 Posters 2.8k Views 2 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.
  • M mpergand
    1 May 2024, 17:13

    @Pfanne
    You may have a look at QButtonGroup or QGroupBox

    P Offline
    P Offline
    Pfanne
    wrote on 1 May 2024, 20:26 last edited by
    #7

    @mpergand

    I take a look at QButtonGroup, this look like the right object for my usecase.
    I tryed this:

    *.h

    private slots:
        void on_ioGroup_clicked(int id);
    
    MainWindow::MainWindow(QWidget* parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    
    {
        ui->setupUi(this);
        QButtonGroup* ioGroup = new QButtonGroup(this);
        ioGroup->addButton(ui->IO_1, 1;
        ioGroup->addButton(ui->IO_2, 2);
        
        connect(ioGroup, SIGNAL(buttonClicked(int)), this, SLOT(on_ioGroup_clicked(int)));
    }
    
    ----
    
    void MainWindow::on_ioGroup_clicked(int id) {
        qDebug() << "id clicked" << id;
    }
        ```
    
    but "on_ioGroup-clicked" will not be executed by clicking on  IO_1 or IO_2.
    J 1 Reply Last reply 1 May 2024, 20:33
    0
    • P Pfanne
      1 May 2024, 20:26

      @mpergand

      I take a look at QButtonGroup, this look like the right object for my usecase.
      I tryed this:

      *.h

      private slots:
          void on_ioGroup_clicked(int id);
      
      MainWindow::MainWindow(QWidget* parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      
      {
          ui->setupUi(this);
          QButtonGroup* ioGroup = new QButtonGroup(this);
          ioGroup->addButton(ui->IO_1, 1;
          ioGroup->addButton(ui->IO_2, 2);
          
          connect(ioGroup, SIGNAL(buttonClicked(int)), this, SLOT(on_ioGroup_clicked(int)));
      }
      
      ----
      
      void MainWindow::on_ioGroup_clicked(int id) {
          qDebug() << "id clicked" << id;
      }
          ```
      
      but "on_ioGroup-clicked" will not be executed by clicking on  IO_1 or IO_2.
      J Offline
      J Offline
      JonB
      wrote on 1 May 2024, 20:33 last edited by
      #8

      @Pfanne
      Use the "modern" syntax for yourconnect()s and you would see there is no buttonClicked(int) with int parameter signal. OTOH there is a QButtonGroup::idClicked(int id) signal.

      P 1 Reply Last reply 1 May 2024, 20:42
      1
      • J JonB
        1 May 2024, 20:33

        @Pfanne
        Use the "modern" syntax for yourconnect()s and you would see there is no buttonClicked(int) with int parameter signal. OTOH there is a QButtonGroup::idClicked(int id) signal.

        P Offline
        P Offline
        Pfanne
        wrote on 1 May 2024, 20:42 last edited by
        #9

        @JonB

        yes, I also saw that "buttonClicked(int)" is not up to date!

        this worked:

        connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);
        

        this not:

            connect(ioGroup, &QButtonGroup::idClicked(int id), this, MainWindow::on_ioGroup_clicked(int id));
        
        P J M 3 Replies Last reply 1 May 2024, 21:01
        0
        • P Pfanne
          1 May 2024, 20:42

          @JonB

          yes, I also saw that "buttonClicked(int)" is not up to date!

          this worked:

          connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);
          

          this not:

              connect(ioGroup, &QButtonGroup::idClicked(int id), this, MainWindow::on_ioGroup_clicked(int id));
          
          P Offline
          P Offline
          Pfanne
          wrote on 1 May 2024, 21:01 last edited by
          #10

          @Pfanne

          finaly this worked:

              connect(ioGroup, SIGNAL(idClicked(int)), this, SLOT(on_ioGroup_clicked(int)));
          
          
          void MainWindow::on_ioGroup_clicked(int id) {
              qDebug() << "id clicked" << id;
              QAbstractButton* cb = ioGroup->button(id);
              qDebug() << "Object" << cb->objectName();
          }
          
          1 Reply Last reply
          0
          • P Pfanne
            1 May 2024, 20:42

            @JonB

            yes, I also saw that "buttonClicked(int)" is not up to date!

            this worked:

            connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);
            

            this not:

                connect(ioGroup, &QButtonGroup::idClicked(int id), this, MainWindow::on_ioGroup_clicked(int id));
            
            J Offline
            J Offline
            JonB
            wrote on 1 May 2024, 21:07 last edited by JonB 5 Jan 2024, 21:07
            #11

            @Pfanne said in ui detect mouse event on objects:

            this worked:
            connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);

            Correct.

            finaly this worked:
            connect(ioGroup, SIGNAL(idClicked(int)), this, SLOT(on_ioGroup_clicked(int)));

            Since you had it correct first why change it?

            P 1 Reply Last reply 2 May 2024, 20:29
            0
            • P Pfanne
              1 May 2024, 20:42

              @JonB

              yes, I also saw that "buttonClicked(int)" is not up to date!

              this worked:

              connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);
              

              this not:

                  connect(ioGroup, &QButtonGroup::idClicked(int id), this, MainWindow::on_ioGroup_clicked(int id));
              
              M Offline
              M Offline
              mpergand
              wrote on 1 May 2024, 21:50 last edited by
              #12

              @Pfanne said in ui detect mouse event on objects:

              connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);

              You must specify an adress (&) here:
              &MainWindow::on_ioGroup_clicked);

              J 1 Reply Last reply 1 May 2024, 22:00
              3
              • M mpergand
                1 May 2024, 21:50

                @Pfanne said in ui detect mouse event on objects:

                connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);

                You must specify an adress (&) here:
                &MainWindow::on_ioGroup_clicked);

                J Offline
                J Offline
                JonB
                wrote on 1 May 2024, 22:00 last edited by
                #13

                @mpergand said in ui detect mouse event on objects:

                &MainWindow::on_ioGroup_clicked);

                OIC I missed that when OP said it was correct.

                M J 2 Replies Last reply 1 May 2024, 22:56
                0
                • J JonB
                  1 May 2024, 22:00

                  @mpergand said in ui detect mouse event on objects:

                  &MainWindow::on_ioGroup_clicked);

                  OIC I missed that when OP said it was correct.

                  M Offline
                  M Offline
                  mpergand
                  wrote on 1 May 2024, 22:56 last edited by mpergand 5 Jan 2024, 22:57
                  #14

                  Hi @JonB

                  Off topic question :
                  How to set text color as you do in red in your posts ?

                  P J 2 Replies Last reply 2 May 2024, 12:05
                  0
                  • M mpergand
                    1 May 2024, 22:56

                    Hi @JonB

                    Off topic question :
                    How to set text color as you do in red in your posts ?

                    P Offline
                    P Offline
                    Pl45m4
                    wrote on 2 May 2024, 12:05 last edited by
                    #15

                    @mpergand said in ui detect mouse event on objects:

                    How to set text color as you do in red in your posts ?

                    ` Text ` = Text


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

                    ~E. W. Dijkstra

                    M 1 Reply Last reply 2 May 2024, 19:07
                    0
                    • M mpergand
                      1 May 2024, 22:56

                      Hi @JonB

                      Off topic question :
                      How to set text color as you do in red in your posts ?

                      J Offline
                      J Offline
                      JonB
                      wrote on 2 May 2024, 15:00 last edited by
                      #16

                      @mpergand said in ui detect mouse event on objects:

                      How to set text color as you do in red in your posts ?

                      Interesting. I don't know and have never set a text color in any of my posts! :) @Pl45m4 post above with red text for Text is the first time I have seen any color.

                      Oh, hang on! Like buttonClicked()? LMAO, until today's forum update that was in green, no wonder I didn't know about red! The "color" is just up to the forum style. The important thing is that code is in monospace font. Use the Code icon (</>) when you are typing in. Or

                      `in-line codecharacters`
                      

                      ```

                      multiline code
                      multiline code
                      

                      ```
                      First one is single-backtick inline, second one is triple-backtick above and below block.

                      P 1 Reply Last reply 2 May 2024, 15:42
                      0
                      • J JonB referenced this topic on 2 May 2024, 15:17
                      • J JonB
                        2 May 2024, 15:00

                        @mpergand said in ui detect mouse event on objects:

                        How to set text color as you do in red in your posts ?

                        Interesting. I don't know and have never set a text color in any of my posts! :) @Pl45m4 post above with red text for Text is the first time I have seen any color.

                        Oh, hang on! Like buttonClicked()? LMAO, until today's forum update that was in green, no wonder I didn't know about red! The "color" is just up to the forum style. The important thing is that code is in monospace font. Use the Code icon (</>) when you are typing in. Or

                        `in-line codecharacters`
                        

                        ```

                        multiline code
                        multiline code
                        

                        ```
                        First one is single-backtick inline, second one is triple-backtick above and below block.

                        P Offline
                        P Offline
                        Pl45m4
                        wrote on 2 May 2024, 15:42 last edited by Pl45m4 5 Feb 2024, 15:43
                        #17

                        @JonB said in ui detect mouse event on objects:

                        Interesting. I don't know and have never set a text color in any of my posts! :) @Pl45m4 post above with red text for Text is the first time I have seen any color.

                        I use this text format every time I mention some Qt term or class. QPushButton, QObject, Q_OBJECT.
                        So did/do you ;-)
                        I don't know what exactly you did when writing these posts, but I used single backticks (don't know how they are called)
                        ` QPushButton ` (now escaped to make them visible)

                        LMAO, until today's forum update that was in green, no wonder I didn't know about red

                        I could swear it was red before, with some kind of red-ish background.
                        At least when used outside of a code section in regular paragraphs.


                        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 2 May 2024, 16:30
                        0
                        • P Pl45m4
                          2 May 2024, 15:42

                          @JonB said in ui detect mouse event on objects:

                          Interesting. I don't know and have never set a text color in any of my posts! :) @Pl45m4 post above with red text for Text is the first time I have seen any color.

                          I use this text format every time I mention some Qt term or class. QPushButton, QObject, Q_OBJECT.
                          So did/do you ;-)
                          I don't know what exactly you did when writing these posts, but I used single backticks (don't know how they are called)
                          ` QPushButton ` (now escaped to make them visible)

                          LMAO, until today's forum update that was in green, no wonder I didn't know about red

                          I could swear it was red before, with some kind of red-ish background.
                          At least when used outside of a code section in regular paragraphs.

                          J Offline
                          J Offline
                          JonB
                          wrote on 2 May 2024, 16:30 last edited by
                          #18

                          @Pl45m4 Maybe. Whatever I thought the original question was how to write in red, rather than in monospace which happens to show as red!

                          1 Reply Last reply
                          1
                          • P Pl45m4
                            2 May 2024, 12:05

                            @mpergand said in ui detect mouse event on objects:

                            How to set text color as you do in red in your posts ?

                            ` Text ` = Text

                            M Offline
                            M Offline
                            mpergand
                            wrote on 2 May 2024, 19:07 last edited by mpergand 5 Feb 2024, 19:10
                            #19

                            @Pl45m4
                            Thanks for the tip :)

                            I finally found the Help button I was looking for yesterday that describes the markdown syntax.

                            1 Reply Last reply
                            0
                            • J JonB
                              1 May 2024, 21:07

                              @Pfanne said in ui detect mouse event on objects:

                              this worked:
                              connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);

                              Correct.

                              finaly this worked:
                              connect(ioGroup, SIGNAL(idClicked(int)), this, SLOT(on_ioGroup_clicked(int)));

                              Since you had it correct first why change it?

                              P Offline
                              P Offline
                              Pfanne
                              wrote on 2 May 2024, 20:29 last edited by Pfanne 5 Feb 2024, 20:29
                              #20

                              @JonB
                              the first version:

                              connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);
                              

                              is without the object ID, implementing the ID in this version a error occurse.

                              M 1 Reply Last reply 2 May 2024, 21:59
                              0
                              • P Pfanne
                                2 May 2024, 20:29

                                @JonB
                                the first version:

                                connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);
                                

                                is without the object ID, implementing the ID in this version a error occurse.

                                M Offline
                                M Offline
                                mpergand
                                wrote on 2 May 2024, 21:59 last edited by
                                #21

                                @Pfanne said in ui detect mouse event on objects:

                                connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);

                                As I said earlier, you have to pass an address:

                                connect(ioGroup, &QButtonGroup::idClicked, this, &MainWindow::on_ioGroup_clicked);

                                1 Reply Last reply
                                2
                                • J JonB
                                  1 May 2024, 22:00

                                  @mpergand said in ui detect mouse event on objects:

                                  &MainWindow::on_ioGroup_clicked);

                                  OIC I missed that when OP said it was correct.

                                  J Offline
                                  J Offline
                                  JonB
                                  wrote on 3 May 2024, 07:52 last edited by
                                  #22

                                  @Pfanne

                                  @JonB said in ui detect mouse event on objects:

                                  @mpergand said in ui detect mouse event on objects:

                                  &MainWindow::on_ioGroup_clicked);

                                  OIC I missed that when OP said it was correct.

                                  You can see for yourself (when it's written in monospace) that in your
                                  connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);

                                  one method reference has a preceding & and the other does not, and thereby tell what you had is not correct.

                                  P 1 Reply Last reply 3 May 2024, 18:02
                                  0
                                  • J JonB
                                    3 May 2024, 07:52

                                    @Pfanne

                                    @JonB said in ui detect mouse event on objects:

                                    @mpergand said in ui detect mouse event on objects:

                                    &MainWindow::on_ioGroup_clicked);

                                    OIC I missed that when OP said it was correct.

                                    You can see for yourself (when it's written in monospace) that in your
                                    connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);

                                    one method reference has a preceding & and the other does not, and thereby tell what you had is not correct.

                                    P Offline
                                    P Offline
                                    Pfanne
                                    wrote on 3 May 2024, 18:02 last edited by
                                    #23

                                    @JonB

                                    connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);
                                    

                                    OK, I think I understand, but this try worked, without ID but it creates a event on every click.
                                    Without the reference (&) to MainWindow....

                                    But it´s OK, this try:

                                    connect(ioGroup, SIGNAL(idClicked(int)), this, SLOT(on_ioGroup_clicked(int)));
                                    

                                    is exactly the way that I use (SIGNAL -> SLOT) for my other connections.

                                    Thanks for your support!

                                    Christian EhrlicherC 1 Reply Last reply 3 May 2024, 18:31
                                    0
                                    • P Pfanne
                                      3 May 2024, 18:02

                                      @JonB

                                      connect(ioGroup, &QButtonGroup::idClicked, this, MainWindow::on_ioGroup_clicked);
                                      

                                      OK, I think I understand, but this try worked, without ID but it creates a event on every click.
                                      Without the reference (&) to MainWindow....

                                      But it´s OK, this try:

                                      connect(ioGroup, SIGNAL(idClicked(int)), this, SLOT(on_ioGroup_clicked(int)));
                                      

                                      is exactly the way that I use (SIGNAL -> SLOT) for my other connections.

                                      Thanks for your support!

                                      Christian EhrlicherC Offline
                                      Christian EhrlicherC Offline
                                      Christian Ehrlicher
                                      Lifetime Qt Champion
                                      wrote on 3 May 2024, 18:31 last edited by
                                      #24

                                      @Pfanne said in ui detect mouse event on objects:

                                      is exactly the way that I use (SIGNAL -> SLOT) for my other connections.

                                      But you should switch to the pmf syntax for your own sake.

                                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                      Visit the Qt Academy at https://academy.qt.io/catalog

                                      P 1 Reply Last reply 4 May 2024, 11:10
                                      1
                                      • Christian EhrlicherC Christian Ehrlicher
                                        3 May 2024, 18:31

                                        @Pfanne said in ui detect mouse event on objects:

                                        is exactly the way that I use (SIGNAL -> SLOT) for my other connections.

                                        But you should switch to the pmf syntax for your own sake.

                                        P Offline
                                        P Offline
                                        Pfanne
                                        wrote on 4 May 2024, 11:10 last edited by
                                        #25

                                        @Christian-Ehrlicher

                                        should I use the pmf syntax only for object events or also for function events too?

                                        P 1 Reply Last reply 4 May 2024, 14:02
                                        0
                                        • P Pfanne
                                          4 May 2024, 11:10

                                          @Christian-Ehrlicher

                                          should I use the pmf syntax only for object events or also for function events too?

                                          P Offline
                                          P Offline
                                          Pl45m4
                                          wrote on 4 May 2024, 14:02 last edited by Pl45m4 5 Apr 2024, 14:04
                                          #26

                                          @Pfanne

                                          What are object or function events from your perspective?
                                          You can't connect events, you connect signals there.
                                          And yes, use the function pointer connection style. Every time you make a signal connection


                                          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

                                          16/26

                                          2 May 2024, 15:00

                                          • Login

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