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. QScrollBar Implementation Uses 2 Styles?

QScrollBar Implementation Uses 2 Styles?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 459 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.
  • Q Offline
    Q Offline
    Qt_User72653
    wrote on last edited by Qt_User72653
    #1

    I'm having an issue related to the value of QStyle::PM_ScrollBarExtent pixel metric so I created a QProxyStyle that just returns 0 for that metric. The issue is QScrollBar has one style for its public implementation, and another for its QScrollBarPrivate implementation, so my proxy style isn't called when I would like it to be.

    Does anyone know why that's the case, and is there a way to override that private style?

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

      Ok, I understand your issue better. The key information missing was that you are using a style sheet. So indeed, there's a dedicated internal style that is used when you set a style sheet.

      Depending on the exact outcome you want, you should do all in your custom style.

      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
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Can you show what is happening when using your proxy ?

        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
        1
        • Q Offline
          Q Offline
          Qt_User72653
          wrote on last edited by Qt_User72653
          #3

          @SGaist, I isolated a related issue with a relatively small example, showing that the displayed scroll bar size doesn't match the returned size for the SC_ScrollBarSlider sub-control rectangle:

          #include <QApplication>
          #include <QDebug>
          #include <QLabel>
          #include <QScrollArea>
          #include <QScrollBar>
          #include <QStyleOption>
          
          class ScrollBar : public QScrollBar {
            public:
          
              ScrollBar(QWidget* parent = nullptr) : QScrollBar(parent) {}
          
            protected:
              void paintEvent(QPaintEvent* event) override {
                auto style_option = QStyleOptionSlider();
                initStyleOption(&style_option);
                auto slider_rect = style()->subControlRect(QStyle::CC_ScrollBar,
                  &style_option, QStyle::SC_ScrollBarSlider);
                qDebug() << slider_rect;
                QScrollBar::paintEvent(event);
              }
          };
          
          int main(int argc, char** argv) {
            auto application = new QApplication(argc, argv);
            auto w = new QScrollArea();
            w->setStyleSheet(QString(R"(
              QScrollBar::vertical {
                border: none;
                width: 13px;
              }
          
              QScrollBar::handle {
                background-color: red;
                min-height: 60px;
              }
          
              QScrollBar::add-line, QScrollBar::sub-line,
              QScrollBar::add-page, QScrollBar::sub-page,
              QScrollBar::up-arrow, QScrollBar::down-arrow {
                background: none;
                border: none;
                height: 0px;
                width: 0px;
              })"));
            auto s = new ScrollBar(w);
            w->setVerticalScrollBar(s);
            auto l = new QLabel("Test Label", w);
            l->setStyleSheet("background-color: aqua;");
            l->setFixedSize(10000, 10000);
            w->setWidget(l);
            w->resize(400, 300);
            w->show();
            return application->exec();
          }
          

          Output and window displayed on Windows 10:

          scrollbar.png

          I would expect the slider_rect in the paintEvent to be 13x60 pixels, and at position (0, 0), but the output shows the rectangle is 13x9 pixels and is at position (0, 17), which is the default geometry without a custom style applied.

          The issue this creates is if I click on the top of the scroll bar (let's say at (0, 0)) and drag down, I have to move the mouse 17 pixels before the scroll bar handle starts to move down.

          I'm not sure if this is a bug or if I'm abusing the QScrollBar in some way, but the goal is to have a button-less scroll bar that moves seamlessly with the mouse.

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

            Ok, I understand your issue better. The key information missing was that you are using a style sheet. So indeed, there's a dedicated internal style that is used when you set a style sheet.

            Depending on the exact outcome you want, you should do all in your custom style.

            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
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved