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 solve the qApp`s QStyleSheetStyle and QProxyStyle issue
Forum Updated to NodeBB v4.3 + New Features

how to solve the qApp`s QStyleSheetStyle and QProxyStyle issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 327 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.
  • S Offline
    S Offline
    spobit
    wrote on last edited by
    #1

    First, I need a scroll bar who is overlapped. the overlapped scroll bar is suspend on viewport, and make it alpha value, then, the viewport will be greater.

    This is the style sheet:

    /* WBOverlapScrollBar */
    /* 各种表,列表用的滚动条,用类名区别于容器滚动条 */
    WBOverlapScrollBar {
        margin: 0px;
        border: none;
        border-radius: 2px;
        padding: 0px;
        background: transparent !important;
    }
    
    WBOverlapScrollBar:vertical
    {
        width: 7px;
        margin: 0px;
        border: 0px;
        padding: 0px;
    }
    
    WBOverlapScrollBar::handle:vertical
    {
        min-height: 60px;
        margin: 0px 1px 0px 2px;
        border: none;
        border-radius: 2px;
        padding: 0px;
        background: rgba(0,0,0,20%);
    }
    
    WBOverlapScrollBar::handle:vertical:hover {
        margin: 0px 1px 0px 0px;
        border-radius: 3px;
        background: rgba(0, 0, 0, 30%);
    }
    
    WBOverlapScrollBar:horizontal
    {
        height: 7px;
        margin: 0px;
        border: 0px;
        padding: 0px;
    }
    
    WBOverlapScrollBar::handle:horizontal
    {
        min-width: 60px;
        margin: 2px 0px 1px 0px;
        border: none;
        border-radius: 2px;
        padding: 0px;
        background: rgba(0,0,0,20%);
    }
    
    WBOverlapScrollBar::handle:horizontal:hover {
        margin: 0px 0px 1px 0px;
        border-radius: 3px;
        background: rgba(0, 0, 0, 30%);
    }
    
    WBOverlapScrollBar::add-line,
    WBOverlapScrollBar::sub-line,
    WBOverlapScrollBar::add-page,
    WBOverlapScrollBar::sub-page {
        width: 0px;
        height: 0px;
        background: transparent;
    }
    

    This is proxy stype:

    #include "wbcontrols_global.h"
    #include <QProxyStyle>
    
    class WB_CONTROLS_EXPORT WBOverlapScrollBarStyle : public QProxyStyle
    {
        Q_OBJECT
    
    public:
        WBOverlapScrollBarStyle(QStyle *style = nullptr);
    
    protected:
        int pixelMetric(PixelMetric m,
                        const QStyleOption *opt = nullptr,
                        const QWidget *widget = nullptr) const override;
    
        int styleHint(StyleHint sh,
                      const QStyleOption *opt = nullptr,
                      const QWidget *w = nullptr,
                      QStyleHintReturn *shret = nullptr) const override;
    };
    
    WBOverlapScrollBarStyle::WBOverlapScrollBarStyle(QStyle *style) : QProxyStyle(style)
    {
    
    }
    
    int WBOverlapScrollBarStyle::pixelMetric(QStyle::PixelMetric m, const QStyleOption *opt, const QWidget *widget) const
    {
        ///
        /// 设置滚动条层叠于视口上
        ///
        if (QStyle::PM_ScrollView_ScrollBarOverlap == m) {
            return 100;
        }
        return QProxyStyle::pixelMetric(m, opt, widget);
    }
    
    int WBOverlapScrollBarStyle::styleHint(QStyle::StyleHint sh, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *shret) const
    {
        ///
        /// 这个枚举文不达意,或是没有实现;
        /// 但是,它可以让滚动条霸占整个表的高度/宽度.
        ///
        if (QStyle::SH_ScrollBar_Transient == sh) {
           // int i = 0;
           return 1;
        }
        return QProxyStyle::styleHint(sh, opt, w, shret);
    }
    

    My app has a qApp level`s style sheet, when I type style sheet of WBOverlapScrollBar in it, WBOverlapScrollBarStyle will be not effect; it will be effect but type it to other position. I have some idea, but no time to check. any experence to me, Thanks!

    void QWidget::setStyle(QStyle *style)
    {
        Q_D(QWidget);
        setAttribute(Qt::WA_SetStyle, style != 0);
        d->createExtra();
    #ifndef QT_NO_STYLE_STYLESHEET
        if (QStyleSheetStyle *styleSheetStyle = qt_styleSheet(style)) {
            //if for some reason someone try to set a QStyleSheetStyle, ref it
            //(this may happen for exemple in QButtonDialogBox which propagates its style)
            styleSheetStyle->ref();
            d->setStyle_helper(style, false);
        } else if (qt_styleSheet(d->extra->style) || !qApp->styleSheet().isEmpty()) {
            // if we have an application stylesheet or have a proxy already, propagate
            d->setStyle_helper(new QStyleSheetStyle(style), true);
        } else
    #endif
            d->setStyle_helper(style, false);
    }
    
    S 1 Reply Last reply
    0
    • S spobit

      First, I need a scroll bar who is overlapped. the overlapped scroll bar is suspend on viewport, and make it alpha value, then, the viewport will be greater.

      This is the style sheet:

      /* WBOverlapScrollBar */
      /* 各种表,列表用的滚动条,用类名区别于容器滚动条 */
      WBOverlapScrollBar {
          margin: 0px;
          border: none;
          border-radius: 2px;
          padding: 0px;
          background: transparent !important;
      }
      
      WBOverlapScrollBar:vertical
      {
          width: 7px;
          margin: 0px;
          border: 0px;
          padding: 0px;
      }
      
      WBOverlapScrollBar::handle:vertical
      {
          min-height: 60px;
          margin: 0px 1px 0px 2px;
          border: none;
          border-radius: 2px;
          padding: 0px;
          background: rgba(0,0,0,20%);
      }
      
      WBOverlapScrollBar::handle:vertical:hover {
          margin: 0px 1px 0px 0px;
          border-radius: 3px;
          background: rgba(0, 0, 0, 30%);
      }
      
      WBOverlapScrollBar:horizontal
      {
          height: 7px;
          margin: 0px;
          border: 0px;
          padding: 0px;
      }
      
      WBOverlapScrollBar::handle:horizontal
      {
          min-width: 60px;
          margin: 2px 0px 1px 0px;
          border: none;
          border-radius: 2px;
          padding: 0px;
          background: rgba(0,0,0,20%);
      }
      
      WBOverlapScrollBar::handle:horizontal:hover {
          margin: 0px 0px 1px 0px;
          border-radius: 3px;
          background: rgba(0, 0, 0, 30%);
      }
      
      WBOverlapScrollBar::add-line,
      WBOverlapScrollBar::sub-line,
      WBOverlapScrollBar::add-page,
      WBOverlapScrollBar::sub-page {
          width: 0px;
          height: 0px;
          background: transparent;
      }
      

      This is proxy stype:

      #include "wbcontrols_global.h"
      #include <QProxyStyle>
      
      class WB_CONTROLS_EXPORT WBOverlapScrollBarStyle : public QProxyStyle
      {
          Q_OBJECT
      
      public:
          WBOverlapScrollBarStyle(QStyle *style = nullptr);
      
      protected:
          int pixelMetric(PixelMetric m,
                          const QStyleOption *opt = nullptr,
                          const QWidget *widget = nullptr) const override;
      
          int styleHint(StyleHint sh,
                        const QStyleOption *opt = nullptr,
                        const QWidget *w = nullptr,
                        QStyleHintReturn *shret = nullptr) const override;
      };
      
      WBOverlapScrollBarStyle::WBOverlapScrollBarStyle(QStyle *style) : QProxyStyle(style)
      {
      
      }
      
      int WBOverlapScrollBarStyle::pixelMetric(QStyle::PixelMetric m, const QStyleOption *opt, const QWidget *widget) const
      {
          ///
          /// 设置滚动条层叠于视口上
          ///
          if (QStyle::PM_ScrollView_ScrollBarOverlap == m) {
              return 100;
          }
          return QProxyStyle::pixelMetric(m, opt, widget);
      }
      
      int WBOverlapScrollBarStyle::styleHint(QStyle::StyleHint sh, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *shret) const
      {
          ///
          /// 这个枚举文不达意,或是没有实现;
          /// 但是,它可以让滚动条霸占整个表的高度/宽度.
          ///
          if (QStyle::SH_ScrollBar_Transient == sh) {
             // int i = 0;
             return 1;
          }
          return QProxyStyle::styleHint(sh, opt, w, shret);
      }
      

      My app has a qApp level`s style sheet, when I type style sheet of WBOverlapScrollBar in it, WBOverlapScrollBarStyle will be not effect; it will be effect but type it to other position. I have some idea, but no time to check. any experence to me, Thanks!

      void QWidget::setStyle(QStyle *style)
      {
          Q_D(QWidget);
          setAttribute(Qt::WA_SetStyle, style != 0);
          d->createExtra();
      #ifndef QT_NO_STYLE_STYLESHEET
          if (QStyleSheetStyle *styleSheetStyle = qt_styleSheet(style)) {
              //if for some reason someone try to set a QStyleSheetStyle, ref it
              //(this may happen for exemple in QButtonDialogBox which propagates its style)
              styleSheetStyle->ref();
              d->setStyle_helper(style, false);
          } else if (qt_styleSheet(d->extra->style) || !qApp->styleSheet().isEmpty()) {
              // if we have an application stylesheet or have a proxy already, propagate
              d->setStyle_helper(new QStyleSheetStyle(style), true);
          } else
      #endif
              d->setStyle_helper(style, false);
      }
      
      S Offline
      S Offline
      spobit
      wrote on last edited by
      #2

      @spobit
      SH_ScrollBar_Transient has the declaration:

      Determines if the style supports transient scroll bars. Transient scroll bars appear when the content is scrolled and disappear when they are no longer needed.
      

      But, it does not work on windows 10 qt-5.12.4.

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

        Hi
        I thought only MacOs has support for
        SH_ScrollBar_Transient
        not Windows. 10 ?

        Maybe others know for sure if it can work or not.

        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