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. Double Click Signal
Forum Updated to NodeBB v4.3 + New Features

Double Click Signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 5 Posters 1.2k Views 1 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.
  • O Offline
    O Offline
    ostrichking371
    wrote on last edited by
    #1

    I am making an app where I need to know when a slider is double clicked. When I use the QWidget signal: mouseDoubleClickedEvent, the programs errors and says that it is a protected function. I am new to c++ and can’t find documentation on this issue. I know this is very simple but please help!

    Christian EhrlicherC 1 Reply Last reply
    0
    • O ostrichking371

      I am making an app where I need to know when a slider is double clicked. When I use the QWidget signal: mouseDoubleClickedEvent, the programs errors and says that it is a protected function. I am new to c++ and can’t find documentation on this issue. I know this is very simple but please help!

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ostrichking371 said in Double Click Signal:

      QWidget signal: mouseDoubleClickedEvent,

      This is a function, not a signal. You have to reimplement this function when you want custom functionality.

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

      O 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @ostrichking371 said in Double Click Signal:

        QWidget signal: mouseDoubleClickedEvent,

        This is a function, not a signal. You have to reimplement this function when you want custom functionality.

        O Offline
        O Offline
        ostrichking371
        wrote on last edited by
        #3

        @Christian-Ehrlicher again…new to c++. What does this mean? Aren’t signals just empty functions that can be detected by other widgets when they get called? I mean, the EMIT macro is empty, it just calls the function.

        Christian EhrlicherC 1 Reply Last reply
        0
        • O ostrichking371

          @Christian-Ehrlicher again…new to c++. What does this mean? Aren’t signals just empty functions that can be detected by other widgets when they get called? I mean, the EMIT macro is empty, it just calls the function.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ostrichking371 said in Double Click Signal:

          Aren’t signals just empty functions that can be detected by other widgets when they get called?

          No, see https://doc.qt.io/qt-6/signalsandslots.html

          And for overriding see https://www.simplilearn.com/tutorials/cpp-tutorial/function-overriding-in-cpp

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

          O 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            @ostrichking371 said in Double Click Signal:

            Aren’t signals just empty functions that can be detected by other widgets when they get called?

            No, see https://doc.qt.io/qt-6/signalsandslots.html

            And for overriding see https://www.simplilearn.com/tutorials/cpp-tutorial/function-overriding-in-cpp

            O Offline
            O Offline
            ostrichking371
            wrote on last edited by
            #5

            @Christian-Ehrlicher so they are functions... "Signals are public access functions" (Qt doc). I still dont understand how i can detect double clicking and emit a signal.

            JonBJ 1 Reply Last reply
            0
            • O ostrichking371

              @Christian-Ehrlicher so they are functions... "Signals are public access functions" (Qt doc). I still dont understand how i can detect double clicking and emit a signal.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @ostrichking371
              Because QWidget does not itself emit a signal for this you must:

              1. Subclass QWidget precisely so that you can...
              2. ... override the protected QWidget::mouseDoubleClickEvent().
              3. Declare a function named, say, doubleClicked(), in the signals: section of the class declaration in the .h file.
              4. emit doubleClicked() in the body of your overridden mouseDoubleClickEvent().
              5. connect() a slot to that signal just like you would for any other inbuilt Qt signal.
              O 1 Reply Last reply
              1
              • JonBJ JonB

                @ostrichking371
                Because QWidget does not itself emit a signal for this you must:

                1. Subclass QWidget precisely so that you can...
                2. ... override the protected QWidget::mouseDoubleClickEvent().
                3. Declare a function named, say, doubleClicked(), in the signals: section of the class declaration in the .h file.
                4. emit doubleClicked() in the body of your overridden mouseDoubleClickEvent().
                5. connect() a slot to that signal just like you would for any other inbuilt Qt signal.
                O Offline
                O Offline
                ostrichking371
                wrote on last edited by
                #7

                @JonB Thanks for such a helpful comment! Heres the function i wrote, but it still doesn't work.

                void QAdvSlider::mouseDoubleClickEvent(QMouseEvent *event) {
                    emit doubleClicked();
                }
                
                JonBJ 1 Reply Last reply
                0
                • O ostrichking371

                  @JonB Thanks for such a helpful comment! Heres the function i wrote, but it still doesn't work.

                  void QAdvSlider::mouseDoubleClickEvent(QMouseEvent *event) {
                      emit doubleClicked();
                  }
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @ostrichking371
                  In principle that should be right, what does "still doesn't work" mean? You must explain this sort of phrase when asking for help. First thing is to make sure the emit line is being hit.

                  QAdvSlider

                  Try not to start your own class names with Q, leave that to Qt itself.

                  O 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @ostrichking371
                    In principle that should be right, what does "still doesn't work" mean? You must explain this sort of phrase when asking for help. First thing is to make sure the emit line is being hit.

                    QAdvSlider

                    Try not to start your own class names with Q, leave that to Qt itself.

                    O Offline
                    O Offline
                    ostrichking371
                    wrote on last edited by
                    #9

                    @JonB I fixed it!! The signal is emitted at double click, but only if i click the blank areas. If i double click the slider handle, it doesnt work, but this is what i want. Is it possible to have it work when you double click the slider handle.

                    jsulmJ 1 Reply Last reply
                    0
                    • O ostrichking371

                      @JonB I fixed it!! The signal is emitted at double click, but only if i click the blank areas. If i double click the slider handle, it doesnt work, but this is what i want. Is it possible to have it work when you double click the slider handle.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @ostrichking371 said in Double Click Signal:

                      Is it possible to have it work when you double click the slider handle.

                      Yes, do the same: subclass QSlider, override mouseDoubleClickEvent (don't forget to call mouseDoubleClickEvent from QSlider!), emit the signal there and use your subclass instead of QSlider.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      Pl45m4P 1 Reply Last reply
                      3
                      • jsulmJ jsulm

                        @ostrichking371 said in Double Click Signal:

                        Is it possible to have it work when you double click the slider handle.

                        Yes, do the same: subclass QSlider, override mouseDoubleClickEvent (don't forget to call mouseDoubleClickEvent from QSlider!), emit the signal there and use your subclass instead of QSlider.

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

                        @jsulm said in Double Click Signal:

                        Yes, do the same: subclass QSlider, override mouseDoubleClickEvent (don't forget to call mouseDoubleClickEvent from QSlider!), emit the signal there and use your subclass instead of QSlider.

                        I think the focus was on "if I double click the slider handle"...
                        The mouseEvents are sent when clicking the widget itself, but when clicking the handle sub-control, sliderPressed() is emitted, which will "eat" the mouse clicks.

                        @ostrichking371 One thing you could do is employing the sliderPressed() signal to start a timer and measure the time span until the signal is emitted for the second time. If it's in your desired double-click range, do what you are trying to do afterwards, else do nothing so it's treated as single click to grab the slider handle.


                        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
                        2

                        • Login

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