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. [SOLVED] QSlider handle size after stylesheet

[SOLVED] QSlider handle size after stylesheet

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 8.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.
  • B Offline
    B Offline
    butterface
    wrote on last edited by
    #1

    Is it possible to get the size of the handle of a QSlider if a stylesheet changed it?

    The following code seems only to work if nothing changed the handles size

    @
    QStyleOptionSlider opt;
    initStyleOption(&opt);
    QRect handle = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle);
    @

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

      Hi,

      You could parse the stylesheet for that information

      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
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        [quote author="butterface" date="1389193865"]
        The following code seems only to work if nothing changed the handles size
        [/quote]
        why doesn't this code work for you?
        How does the output differ from what you expect?
        How does your stylesheet look like?

        --- 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
        • B Offline
          B Offline
          butterface
          wrote on last edited by
          #4

          I don't know why.

          The output gives me a width of the handle of 15 but it should be 18.

          @
          QSlider::handle:horizontal {
          background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 #8f8f8f);
          border: 1px solid #0c457e;
          width: 18px;
          margin: -2px 0;
          border-radius: 3px;
          }
          @

          1 Reply Last reply
          0
          • B Offline
            B Offline
            butterface
            wrote on last edited by
            #5

            @SGaist Of course this would be an option but I would prefer to ask the slider itself for its handle size.

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

              seems that setting the handle size via stylesheet style isn't possible at all.
              This is a fixed pixel metric (QStyle::PM_SliderLength) value in the platform styles (at least on Windows).

              --- 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
              • B Offline
                B Offline
                butterface
                wrote on last edited by
                #7

                That is not correct. width changes the size of the handle.

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

                  correct, my fault.
                  I've just tested the style definition you posted, and this isn't working as it is (only when you also style the slider's groove i think)

                  To come back to your problem:
                  Your code is almost correct. Just keep in mind that every time you call QStyle methods and an optional QWidget parameter is available you need to pass it:
                  @
                  QStyleOptionSlider opt;
                  initStyleOption(&opt);
                  QRect handle = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
                  @
                  This will work.

                  --- 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
                  • B Offline
                    B Offline
                    butterface
                    wrote on last edited by
                    #9

                    I should have posted the whole slider style.

                    The this indeed fixed the problem. Thanks!

                    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