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. Retain width of vertical scrollbar when hidden in a QScrollArea

Retain width of vertical scrollbar when hidden in a QScrollArea

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 267 Views
  • 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.
  • Jonas KvingeJ Offline
    Jonas KvingeJ Offline
    Jonas Kvinge
    wrote on last edited by
    #1

    Hi,

    When using a QWidget inside a layout on a QScrollArea with horizontal scrollbar disabled and vertical scrollbar set to Qt::ScrollBarAsNeeded, it causes a resize of the width each time the vertical scrollbar is automatically activated/deactivated.
    I can't find a way to keep the width of vertical scrollbar when it's hidden.
    I've tried the following code:

    QSizePolicy size_policy = scrollarea_->verticalScrollBar()->sizePolicy();
    size_policy.setRetainSizeWhenHidden(true);
    scrollarea_->verticalScrollBar()->setSizePolicy(size_policy);
    

    Or is there an alternative solution using layout or spacer that can fill the gap of the of the scrollbar to avoid the resize of the width?

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      Try it out to set a fixed width with stylesheet of QScrollBar:vertical
      https://doc.qt.io/qt-6/stylesheet-examples.html

      1 Reply Last reply
      1
      • Jonas KvingeJ Offline
        Jonas KvingeJ Offline
        Jonas Kvinge
        wrote on last edited by
        #3

        The width of the scrollbar is changed but it still doesn't retain the size when hidden.

        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