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. How can i call a function when the slider stops
Forum Updated to NodeBB v4.3 + New Features

How can i call a function when the slider stops

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.6k 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.
  • S Offline
    S Offline
    salvador
    wrote on last edited by
    #1

    Hey,
    i have implemented a grid and i have added two QAbstractScrollBar items. One for vertical scrolling and one for horizontal scrolling. I read all th signal, events and action that are related with these classes but i can't find how i "listen" when the slider stop moving. More specfically i want when the slider stops wait for 2 seconds and then call a function.

    ty

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      AFAIK there isn't.

      What you could do is to have a slot connected to valueChanged(int) and restart a QTimer (connected to the function you want) in there. So once you don't move the slider for a few second, the timer will timeout.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        salvador
        wrote on last edited by
        #3

        I want, if possible, to avoid the valueChanged(int) signal because it will be emmited not only when i scoll the slider but when i move the slider for a single step which i don't want.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then what about a combination of mouseMove and mouseRelease event ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            salvador
            wrote on last edited by
            #5

            It sounds good but i want the same function to be called when the wheell scrolling stops not just when the slider scrolling stops. Also i would like somenthing like mouseRelease ans mouseNotMove events. Not mouseMove event

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then also look for the wheelEvent.

              You'll have to do the "not moved" detection yourself based on the various input you get.

              Then again, are you sure it's not better to base your unmoved logic on the valueChanged(int) signal ? Don't start the timer if the delta between the last move and this one is a single step.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                salvador
                wrote on last edited by
                #7

                I was thinking something like this:
                @void handleVScrollAction(int action)
                {
                if(action == QAbstractSlider::SliderSingleStepAdd)
                {
                setValueVertical();
                requestSlot();
                }
                else if(action == QAbstractSlider::SliderSingleStepSub)
                {
                setValueVertical();
                requestSlot();
                }
                else if(action == QAbstractSlider::SliderMove)
                {
                drawGrid();
                setValueVertical();
                }
                else if(action == QAbstractSlider::SliderNoAction)
                {
                //start timer
                //when times ends
                //call requestSlot
                }
                }@

                But the QAbstractSlider::SliderNoAction doesn't work as i expexted to. How can i implement your suggetion? When the valueChanged signal is emmited the new value, as far as i know, is instantly stored to the QScrollBar.

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  maybe you are thinking too much straight forward ;)
                  Do like SGaist suggested in his first post:
                  @
                  m_Timer.setSingleShot(true);
                  m_Timer.setTimeout(2000);
                  connect(&m_Timer, SIGNAL(timeout()), this, SLOT(mySlot()));

                  ....

                  void handleVScrollAction(int action)
                  {
                  switch(action)
                  {
                  case QAbstractSlider::SliderSingleStepAdd:
                  case QAbstractSlider::SliderSingleStepSub:
                  setValueVertical();
                  requestSlot();
                  break;
                  case QAbstractSlider::SliderMove:
                  drawGrid();
                  setValueVertical();

                          m_Timer.start();   //if the timer is already running it is restarted automatically
                      break;
                  }
                  

                  }
                  @

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    salvador
                    wrote on last edited by
                    #9

                    it worked! Thanks a lot ;)

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      salvador
                      wrote on last edited by
                      #10

                      I am opening again because there is one more problem. When i am press the arrow key to scroll the app triggers one of these ations:
                      @case QAbstractSlider::SliderSingleStepAdd:
                      case QAbstractSlider::SliderSingleStepSub:@
                      The first time i press the arrow it does not do anything the second time it moves one step. In addition, when i stop pushing the down arrow key and i want to go up, i press the up arrow key. The first time i press the key it goes down instead of up, the second time it goes up as it should be. Is there any logical explanation for this?

                      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