Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-111314

Adding padding to QSlider does not work on Fusion style

    XMLWordPrintable

Details

    • Windows
    • 8594fe1b8 (dev), 9622c7797 (6.7)

    Description

      Hi,

      We are trying to develop a QSlider derivative which shows labels below the ticks.

      We are currently only supporting a horizontal slider.

      To avoid clipping the labels of the first and last tick, we added some margin/padding to the left and right of the original slider.

      To do this, we noted in the QSlider implementation of paintEvent (line 282) that the rectangle is derived from initStyleOption before it is passed to QStylePainter.drawComplexControl for the actual drawing.

      We have used this mechanism to add the margin we require by re-implementing initStyleOption in our PySide code:

      def initStyleOption(self, option):
          """Re-implement to provide space for the text below the slider, and the 
          margin to the left and right (as usual, from the perspective of 
          horizontal sliders).
              
          This method is called by the default paintEvent. Initialise as normal,
          then restore the normal height (observed on Windows) to trick 
          QSlider.paintEvent into ignoring the true height. This leaves room for
          us to draw the labels below.
          """
          super().initStyleOption(option)
          option.rect.setHeight(27)
          option.rect.adjust(+self.margin, 0, -self.margin, 0)
      

      On my default platform-style ("windowsvista") this work nicely; please see first attachment.

      However, with the style Fusion the ticks and the central blue spine are shifted (second attachment).

      We believe this is because when the style draws the ticks, it does not use the rectangle of the option variable defined above, but uses the rectangle of the widget. Please see QFusionStyle::drawComplexControl:

      • Line 1884 for the start of the method.
      • Line 2766 for the start of the slider part.
      • Line 2870 for the start of the tick-drawing code.

      To replicate the code of the "vista" style, we tend to think that on line 2894 the code should not use slider->rect.width() but option->rect.width().
      When we asked about this on the forums, it was suggested this is indeed a bug. Apologies if this is not the case.

      QTBUG-17379 and QTBUG-990 may be related.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            wpietro wpietro
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes