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. Call a function every time scrollbar change value
Forum Updated to NodeBB v4.3 + New Features

Call a function every time scrollbar change value

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 10.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.
  • J Offline
    J Offline
    jk_mk
    wrote on 13 Jun 2011, 16:49 last edited by
    #1

    Hi,

    What I want to do it may be very easy but I really got confused with the docs and the examples. In my application, I have a QScrollbar and I have created a function. The value of the scrollbar is used as a variable in this function. I just want to run this function every time the value of the Qscrollbar is changed and use the value of the QScrollbar as variable at each time the functions runs. I am using Qt Designer and I have read about custom widgets, but I cannot find any solution to my problem. Could somebody help me with this problem?

    Thanks

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on 13 Jun 2011, 17:04 last edited by
      #2

      You can use the "sliderMoved":http://doc.qt.nokia.com/latest/qabstractslider.html#sliderMoved signal and connect it to you function (as long as it is a slot)

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jim_kaiser
        wrote on 13 Jun 2011, 17:08 last edited by
        #3

        This should work..

        Suppose MyClass has the scroll bar.
        @
        // In MyClass.h, declare slot
        slots:
        void handlerFunction(int);

        // In MyClass.cpp, connect
        connect (<your scroll bar obj>, SIGNAL(valueChanged (int)), this, SLOT(handlerFunction(int)));

        // In MyClass.cpp
        void MyClass::handlerFunction(int val)
        {
        // Handling here
        }
        @

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jim_kaiser
          wrote on 13 Jun 2011, 17:10 last edited by
          #4

          @loladiro: From the documentation it seems the valueChanged would be a better choice.

          sliderMoved

          bq. This signal is emitted when sliderDown is true and the slider moves. This usually happens when the user is dragging the slider.

          valueChanged

          bq. This signal is emitted when the slider value has changed, with the new slider value as argument.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            loladiro
            wrote on 13 Jun 2011, 17:11 last edited by
            #5

            Depending on what you want to do you can use either signal. The sliderMoved signal is only emitted if the user actually moved it (not if you set it within your application). But as I said it depends on your specific use case.

            EDIT: jim_kaiser: you are really fast

            EDIT2: jim_kaiser You're right, it won't (didn't think about that part). Thanks for the info.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jim_kaiser
              wrote on 13 Jun 2011, 17:12 last edited by
              #6

              Yes, thats true, but will the sliderMoved be emitted when the user doesn't drag the slider, but instead uses the buttons on the ends?

              EDIT: @loladiro: Hehe... well just got here recently.. been coding Qt and solving my problems myself for a few years (Just looooove Qt and what the community has achieved).. and excited to be here.. Its just great to see this community active.. wasn't a member of the QtCentre.. so my first interaction with the Qt community.. :) Not the right place to post this but well wanted to say it somewhere!

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on 13 Jun 2011, 17:13 last edited by
                #7

                closed due to duplicate of "this thread":http://developer.qt.nokia.com/forums/viewthread/6380/

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0

                1/7

                13 Jun 2011, 16:49

                • Login

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