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

QProxyStyle will not work properly with another proxy style as a baseStyle

    XMLWordPrintable

Details

    • 61c3f3539c3d2d7dc867c3fef0270a2f5c9ed376 (qt/qtbase/dev) 1580c84e1a3c6658f317f7bc78c64575160c1d65 (qt/qtbase/6.0) 76d7d86a3fbe5bb09c5c070ab11567e4f329185b (qt/tqtc-qtbase/tqtc/lts-5.15)

    Description

      We were composing new styles from our existing custom style and discovered that even though everything compiled there were unexpected problems at runtime if the baseStyle was another QProxyStyle subclass instance.

       

      We made simple example by creating a modified version of the standard Qt styles example. This version creates a simple subclass of QProxyStyle that only changes the pixelMetric for spacing for radio button labels.

      #include "norwegianwoodproxystyle.h"
      #include "norwegianwoodstyle.h"
      
      NorwegianWoodProxyStyle::NorwegianWoodProxyStyle()
          : QProxyStyle(new NorwegianWoodStyle)
      {
          setObjectName("NorwegianWoodProxy");
      }
      
      int NorwegianWoodProxyStyle::pixelMetric(PixelMetric metric,
                                          const QStyleOption *option,
                                          const QWidget *widget) const
      {
          switch (metric)
          {
              case PM_RadioButtonLabelSpacing:
                  return 32;
      
              default:
                  return QProxyStyle::pixelMetric(metric, option, widget);
          }
      }
      

      The expected behavior is for the new style to be exactly the same as the NorwegianWoodStyle but with a larger indent for radio buttons. 

       

      What actually happens is there is no difference between the two styles. This happens because NorwegianWoodProxyStyle::pixelMetric is never called with metric set to PM_RadioButtonLabelSpacing because the lower level QCommonStyle code access to the proxy() method returns the NorwegianWoodStyle instance instead of NorwegianWoodProxyStyle.

       

      The source of the issue is there is no code QProxyStyle constructors or QProxyStyle::setBaseStyle to update any of baseStyle's proxies if the baseStyle of the proxy is-a QProxyStyle.

      We already have a patch that resolves the issue. The attached patch is for qtcore based on Qt 5.12.7 but I expect this is the same for 5.15 as well.

      Attachments

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

        Activity

          People

            tpochep Timur Pocheptsov
            tom.ransdell Tom Ransdell
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes