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 can I permanently show scrollbars?
Forum Updated to NodeBB v4.3 + New Features

How can I permanently show scrollbars?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 4.5k Views 2 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.
  • K Offline
    K Offline
    Kerndog73
    wrote on last edited by Kerndog73
    #1

    I want a set of scroll bars to be a permanent part of the UI. I want them to always be visible. The following snippet is not enough.

    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    

    I want the scroll bars to be visible even when they aren't necessary. How can I achieve this?

    jsulmJ 1 Reply Last reply
    0
    • K Kerndog73

      I want a set of scroll bars to be a permanent part of the UI. I want them to always be visible. The following snippet is not enough.

      setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
      setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
      

      I want the scroll bars to be visible even when they aren't necessary. How can I achieve this?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Kerndog73 Are you sure this scrollArea is the correct one? It looks like it is allocated on the stack. Where do you execute this code and can you show it?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Kerndog73 Are you sure this scrollArea is the correct one? It looks like it is allocated on the stack. Where do you execute this code and can you show it?

        K Offline
        K Offline
        Kerndog73
        wrote on last edited by
        #3

        @jsulm My actual code is slightly different. I'm deriving from QScrollArea. I'm also using custom QScrollBars. This is more similar to what I'm doing:

        class ScrollBar final : public QScrollBar {
        public:
          ScrollBar(Qt::Orientation orient, QWidget *parent)
            : QScrollBar{orient, parent} {}
        };
        
        class ScrollArea final : public QScrollArea {
        public:
          explicit ScrollArea(QWidget *parent)
            : QScrollArea{parent} {
            setVerticalScrollBar(new ScrollBar{Qt::Vertical, this});
            setHorizontalScrollBar(new ScrollBar{Qt::Horizontal, this});
            setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
            setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
          }
        };
        

        Is Qt::ScrollBarAlwaysOn supposed to make the scrollbar always visible or am I experiencing expected behaviour?

        jsulmJ 1 Reply Last reply
        0
        • K Kerndog73

          @jsulm My actual code is slightly different. I'm deriving from QScrollArea. I'm also using custom QScrollBars. This is more similar to what I'm doing:

          class ScrollBar final : public QScrollBar {
          public:
            ScrollBar(Qt::Orientation orient, QWidget *parent)
              : QScrollBar{orient, parent} {}
          };
          
          class ScrollArea final : public QScrollArea {
          public:
            explicit ScrollArea(QWidget *parent)
              : QScrollArea{parent} {
              setVerticalScrollBar(new ScrollBar{Qt::Vertical, this});
              setHorizontalScrollBar(new ScrollBar{Qt::Horizontal, this});
              setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
              setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
            }
          };
          

          Is Qt::ScrollBarAlwaysOn supposed to make the scrollbar always visible or am I experiencing expected behaviour?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Kerndog73 From documentation (https://doc.qt.io/qt-5/qt.html#ScrollBarPolicy-enum):
          "QAbstractScrollArea always shows a scroll bar. This property is ignored on systems with transient scroll bars (e.g., on Mac from version 10.7)."

          On which platform are you?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          K 1 Reply Last reply
          1
          • jsulmJ jsulm

            @Kerndog73 From documentation (https://doc.qt.io/qt-5/qt.html#ScrollBarPolicy-enum):
            "QAbstractScrollArea always shows a scroll bar. This property is ignored on systems with transient scroll bars (e.g., on Mac from version 10.7)."

            On which platform are you?

            K Offline
            K Offline
            Kerndog73
            wrote on last edited by Kerndog73
            #5

            @jsulm I'm on a mac. Is there any way around this? Will I have to make my own scroll area from scratch if I want this behaviour? Maybe the scroll area could emulate scroll bars by setting content margins, responding to mouse events and painting? There must be a better way!

            BTW, how do I earn reputation on this site? Having to wait 10 minutes to reply is kind of annoying.

            jsulmJ 1 Reply Last reply
            1
            • K Kerndog73

              @jsulm I'm on a mac. Is there any way around this? Will I have to make my own scroll area from scratch if I want this behaviour? Maybe the scroll area could emulate scroll bars by setting content margins, responding to mouse events and painting? There must be a better way!

              BTW, how do I earn reputation on this site? Having to wait 10 minutes to reply is kind of annoying.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Kerndog73 Maybe you could use https://doc.qt.io/Qt-5/qscrollbar.html instead of the scroll area, but this means more work. Also, do you really want to work against platform UI design guidelines?

              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
                #7

                Hi,

                I agree with @jsulm. What is your goal behind showing these scrollbars permanently on macOS ? It's been 7 versions since they are transient and everybody will expect that. Showing them permanently will make your application feel broken to your users.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                K 1 Reply Last reply
                1
                • SGaistS SGaist

                  Hi,

                  I agree with @jsulm. What is your goal behind showing these scrollbars permanently on macOS ? It's been 7 versions since they are transient and everybody will expect that. Showing them permanently will make your application feel broken to your users.

                  K Offline
                  K Offline
                  Kerndog73
                  wrote on last edited by
                  #8

                  @SGaist @jsulm I've been using macOS since Mavericks. I've given this quite a bit of thought and I think you're right. I should accept the defaults in this case.

                  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