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. Three-click
Forum Updated to NodeBB v4.3 + New Features

Three-click

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 495 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.
  • A Offline
    A Offline
    AndrzejB
    wrote on last edited by
    #1

    How to handle three clicks one after the other?
    If between 2nd and 3rd click is large time interval - is not three click, must be enough short time interval.
    I wanna use it to select current line.

    Chris KawaC 1 Reply Last reply
    0
    • A AndrzejB

      How to handle three clicks one after the other?
      If between 2nd and 3rd click is large time interval - is not three click, must be enough short time interval.
      I wanna use it to select current line.

      Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      Use a QElapsedTimer to measure time between mouse releases. If it's under some delta increase click counter. If above reset it. When you reach a count of 3 emit a triple click signal.

      Something like this:

      void SomeWidget::mouseReleaseEvent(QMouseEvent* event)
      {
           ParentClass::mouseReleaseEvent(event);
      
           qint64 elapsed = someTimer.restart(); //someTimer is QElapsedTimer member
           if (elapsed < someDelta)
              ++clicks;
           else
              clicks = 1;
           
           switch(clicks) {
              case 1: emit singleClick(); break;
              case 2: emit doubleClick(); break;
              case 3: emit tripleClick(); break;
              case 4: emit quadrupleClick(); break;
              ...
           }
      }
      
      
      1 Reply Last reply
      3
      • A Offline
        A Offline
        AndrzejB
        wrote on last edited by
        #3

        Will no conflict with standard
        QWidget:: mouseDoubleClickEvent?
        will two times QWidget:: mouseReleaseEvent and one QWidget:: mouseDoubleClickEvent ?

        Chris KawaC S 2 Replies Last reply
        0
        • A AndrzejB

          Will no conflict with standard
          QWidget:: mouseDoubleClickEvent?
          will two times QWidget:: mouseReleaseEvent and one QWidget:: mouseDoubleClickEvent ?

          Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #4

          @AndrzejB It was just an example. You don't have to make all those signals. You can just leave the triple signal and use the default ones for single and double clicks, or you can make a mouseTripleClickEvent or call a callback function or do whatever else you need. I just gave you a way to detect the third click. How you handle it when you do is up to you.

          1 Reply Last reply
          3
          • A AndrzejB

            Will no conflict with standard
            QWidget:: mouseDoubleClickEvent?
            will two times QWidget:: mouseReleaseEvent and one QWidget:: mouseDoubleClickEvent ?

            S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #5

            @AndrzejB said in Three-click:

            Will no conflict with standard
            QWidget:: mouseDoubleClickEvent?

            Yes, and the double click event will always conflict with the single click. However, the double click can only occur (and thus will be handled) after the single click. In the same way the triple click can only occur after the double click.

            Somewhere in the back of my mind I remember that there is a GUI guideline stating that a double click should not do something totally unrelated to the single click as to not confuse users. The first click positions the cursor; the second click selects the word under the current cursor; the third click would now select the whole line (which will contain the currently selected word). Every click is thus an extension of the previous one. There will be no problem in first handling the single click, after that the double click, and finally the triple click. Otherwise you will have to delay the action of the click using a QTimer and some boolean variables to check if the single wasn't overridden with a double click and the double click wasn't overridden with a triple click.

            1 Reply Last reply
            0

            • Login

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