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. Subclassing QSlider with handle as a Widget
Qt 6.11 is out! See what's new in the release blog

Subclassing QSlider with handle as a Widget

Scheduled Pinned Locked Moved General and Desktop
25 Posts 3 Posters 18.9k 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.
  • C Offline
    C Offline
    cincirin
    wrote on last edited by
    #16

    Yes you can reimplement all of these events in QSlider subclass, and filter all mouse events for handle rect only. Thats all ...
    @
    if (style()->subControlRect(etc).contains(event->pos())
    @

    1 Reply Last reply
    0
    • BlackMambaB Offline
      BlackMambaB Offline
      BlackMamba
      wrote on last edited by
      #17

      ok :)

      And for painting the customwidget, you just instantiate it into the paint method of the subclasses slider and parent it to the subclassed slider?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cincirin
        wrote on last edited by
        #18

        In my example with yes, but I needed three handles not one. With only one handle you can use QSlider signals, events and style(sheets) without any other additional widget(s)

        1 Reply Last reply
        0
        • BlackMambaB Offline
          BlackMambaB Offline
          BlackMamba
          wrote on last edited by
          #19

          And how to you render the customWidget with stylesheet?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cincirin
            wrote on last edited by
            #20

            I'm not using stylesheet in example posted. The default slider handle is rendering by application style and the other two are QLabels with image pixmap.

            1 Reply Last reply
            0
            • BlackMambaB Offline
              BlackMambaB Offline
              BlackMamba
              wrote on last edited by
              #21

              Yes it was as I thought. So how do I do ? :D

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cincirin
                wrote on last edited by
                #22

                What's wrong by subclassing QSlider and reimplement all mouse events you need ? Also you can paint the slider handle either in paint event or using stylesheet. So you have a complete control on slider handle.

                1 Reply Last reply
                0
                • BlackMambaB Offline
                  BlackMambaB Offline
                  BlackMamba
                  wrote on last edited by
                  #23

                  Hello again,

                  I didn't know we could render a widget with QPainter, I never did like that in the past.
                  You are talking about :

                  painter->begin(mycustomwidget); right?

                  Looks like there is also itemChange if I forget about the idea of subclassing a QSlider ....

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cincirin
                    wrote on last edited by
                    #24

                    I think you misunderstood me ( or maybe I misunderstand you :-) )
                    Why do you need a "customwidget" at all ? Consider that your "customwidget" is slider handle. You can render this "handle" in the way you want, also you can intercept mouse events for slider and filter these for "handle" rect.

                    1 Reply Last reply
                    0
                    • BlackMambaB Offline
                      BlackMambaB Offline
                      BlackMamba
                      wrote on last edited by
                      #25

                      Its probably me who misunderstood :D
                      I wanted a separated widget for architecture reasons, to make it modular.
                      Lets say that tomorrow I decide that it will not be a slider but something else.
                      Or I want to render this customwidget in another view in my software ...

                      There are a lot of reasons :)

                      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