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 to draw a custom slider which can be moved by mouse as the Qt intrinsic slider?
Forum Updated to NodeBB v4.3 + New Features

how to draw a custom slider which can be moved by mouse as the Qt intrinsic slider?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.4k 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
    opengpu
    wrote on last edited by
    #1

    how to draw a custom slider which can be moved by mouse as the Qt intrinsic slider?
    i already use QPainter draw some additional effect on the slider-bar.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Is it repeat of the question ?

      As explained earlier, you need to draw things on your own using the paintEvent(..) & handle the mouse events appropriately. Please look at the topics how to write customWidgets.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu
        wrote on last edited by
        #3

        yes.
        i used QGraphicsView before.
        but this time seems no need to use QGraphicsView, and now i am wondering how to draw the slider and how to move it by the mouse
        thank you very much

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          You can do it in graphics view also. Again I'm repeating the following steps.

          1. Look at how custom widgets are created.
          2. re-impliment the paintEvent(...) function.
          3. Draw slider, handler, bar everything on your own.
          4. re-implement mousePress, mouseRelease events.

          Look at the examples I have sent earlier. You are asking the code of the custom slider which you wanted. This will will be very difficult. Here people will help you with specific problem.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • O Offline
            O Offline
            opengpu
            wrote on last edited by
            #5

            ok,i just wonder if not use QGraphicsView, just use the QPainter, is it more simple and easy?
            and can u simply give a hint to to move the slider by the mouse while not use QGraphicsView? check the mouse pos in the slider-rect?

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6
              1. Draw your slider handle in side the paintEvent(..) function.
              2. Handle mouse press, release and move function.
              3. Change the x, y position of your handle inside the mouse event handlers.
              4. Call paintEvent(...) again by calling update(..)

              Look at the pathStroke example. It may help you.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              1
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi
                Just as a note.
                QtCreator comes with something like the gradient thing.
                alt text
                You could look around its code to see how its done.

                1 Reply Last reply
                1

                • Login

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