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 flush QScrollBars with their containing QFrames/QWidgets via. QSS?
Qt 6.11 is out! See what's new in the release blog

How can I flush QScrollBars with their containing QFrames/QWidgets via. QSS?

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

    I have a stylesheet with custom styled QScrollBars. The QSS is as follows (I am aware it's messy):

    QScrollBar, QScrollBar::add-line, QScrollBar::sub-line
    {
        background-color: @button-background;
        border: 1px solid @button-border;
    }
    QScrollBar:horizontal
    {
        padding-left: 13px;
        padding-right: 13px;
    }
    QScrollBar:vertical
    {
        padding-top: 13px;
        padding-bottom: 13px;
    }
    QScrollBar::add-line:hover, QScrollBar::sub-line:hover
    {
        background-color: @button-highlight;
    }
    QScrollBar::add-line:pressed, QScrollBar::sub-line:pressed
    {
        background-color: @button-down;
    }
    QScrollBar
    {
        border-radius: 6px;
    }
    QScrollBar::left-arrow
    {
        image: url(images/left_arrow.png);
    }
    QScrollBar::right-arrow
    {
        image: url(images/right_arrow.png);
    }
    QScrollBar::up-arrow
    {
        image: url(images/up_arrow.png);
    }
    QScrollBar::down-arrow
    {
        image: url(images/down_arrow.png);
    }
    
    QScrollBar::add-line:vertical
    {
        border-top-left-radius: 0px;
        border-top-right-radius: 0px;
        border-bottom-left-radius: 6px;
        border-bottom-right-radius: 6px;
        border-top: 0px;
    }
    QScrollBar::sub-line:vertical
    {
        border-top-left-radius: 6px;
        border-top-right-radius: 6px;
        border-bottom-left-radius: 0px;
        border-bottom-right-radius: 0px;
        border-bottom: 0px;
    }
    QScrollBar::add-line:horizontal
    {
        border-top-left-radius: 0px;
        border-top-right-radius: 6px;
        border-bottom-left-radius: 0px;
        border-bottom-right-radius: 6px;
        border-left: 0px;
    }
    QScrollBar::sub-line:horizontal
    {
        border-top-left-radius: 6px;
        border-top-right-radius: 0px;
        border-bottom-left-radius: 6px;
        border-bottom-right-radius: 0px;
        border-right: 0px;
    }
    
    QScrollBar::handle
    {
        border: 0px solid;
        border-radius: 3px;
        width: 8px;
        margin: 2px;
        background-color: @button-down;
    }
    QScrollBar::handle:vertical
    {
        min-height: 10px;
    }
    QScrollBar::handle:horizontal
    {
        min-width: 10px;
    }
    QScrollBar::handle:hover
    {
        background-color: @button-border;
    }
    

    QScrollArea:

    QGroupBox, QScrollArea
    {
        border: 1px solid @button-border;
        border-radius: 6px;
        background-color: rgba(0,0,0,8);
    }
    

    While the color shouldn't have anything to do with it, the @button-border, @button-highlight, etc. are custom implemented variables.

    When I create a QScrollArea, the scroll bars look like this:
    50bc6762-d58e-4321-a59e-014699d11759-image.png
    I would like for the scroll bars' bottom & right borders to match with the scroll area's borders (i.e. flush).

    I have tried setting the padding of the QScrollArea to a negative value (-1px). This partially worked, but then the borders of the scroll area itself were no longer present.
    Example:
    0fbc8188-6538-481d-858c-e2fe7e2b20a1-image.png

    I have tried setting the margin of the QScrollBars whose parents are QScrollAreas to a negative value (-1px). This screwed up the scroll bar in many ways.
    Example:
    55294cdb-8722-41ff-bccf-bf5c259d0d26-image.png

    • It does not set the subcontrols padding properly.
    • It removes the border on the QScrollBar.
    • It does not extend the width/height of the bars properly, so the 1px issue is still in place on the top & left.
      I believe the first 2 issues are that it isn't applying recursively to the QScrollBar, so I would have to set the property for all the subcontrols and fix the border issue. I feel like there is a better way.

    Every other fix ends with undesirable effects. The Qt Style Sheets Reference and Qt Style Sheets Examples pages say nothing about the QScrollArea.
    This might be easily solved with CSS's inner padding & margin, but from what I can tell there is no such thing in the QSS engine.

    Also, I would also like to set the border color of the black square thing in the bottom right corner to transparent, and for the border-radius to work properly and not clip at the top-left corner.
    Mockup of desired effect:
    a5aa20b1-a625-4006-80e9-205ed42f6960-image.png

    Ewan Green

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @Ewan-Green said in How can I flush QScrollBars with their containing QFrames/QWidgets via. QSS?:

      I would like for the scroll bars' bottom & right borders to match with the scroll area's borders (i.e. flush).

      At first read it looked to me like you are asking for:

      • the horizontal scrollbar to extend rightwards into the small corner box outlined in black, and
      • the vertical scrollbar to downwards into the small corner box outlined in black

      Which bent my mind :)

      Back to the request...
      I think you want to reduce the QScrollBar right (or bottom) margin, not padding, to zero pixels.
      You may also need to reduce the QScrollArea right (or bottom) padding to zero pixels.
      That should put the two border lines immediately next to each other (it's possible that's already the case). You might also tinker with negative one margins on the scroll bars.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Ewan Green
        wrote on last edited by Ewan Green
        #3

        Though I appreciate your suggestion -- they are both already at 0, as you can see here:
        0c5e90c0-8a91-4804-a21e-c6abda2f522c-image.png
        This is me redeclaring margin & padding for the scroll elements so I don't have to pick through the sea of QSS I've written to find where they're initially set :)

        What I want is not for the horizontal or vertical scroll bars to occupy the black square, just for the black square to not be visible. I think you picked up on that by the end of my first post, though. I can definitely see why you think that :p


        Edit: THIS IS STUPID: DONT DO THIS
        As for negative values, I already toyed around with those -- the third screenshot in my initial post was just setting padding: -1px; on the QScrollBars that are children of a QScrollArea. Fleshing out a bit more the way I'd imagine would fix it just does this:
        30668a7b-4271-4da4-b3ac-d5da42bece01-image.png
        Yeah, it fixes the border issue, but creates a plethora of other ones. The sub-line and add-line subcontrols seem to take over the whole horizontal/vertical space, and I cannot access the handle (that also happens to be oversized).

        DO THIS INSTEAD:

        QScrollArea QScrollBar::horizontal
        {
            margin: -1px;
            margin-top: 1px;
        }
        QScrollArea QScrollBar::vertical
        {
            margin: -1px;
            margin-left: 1px;
        }
        

        As long as your subcontrol positions & sizes are set properly, there should not be any setting of margins needed beyond this.


        The two border lines are what's already happening without any extra QSS, that's what my first screenshot was. Thank you for your suggestions!

        Edit: I forgot about the fact that I had already set margins for the scroll bars. Making the margins negative does not break anything. It does work, but I would like to know if there is a better way than manually setting margins of specific widgets' children before I close this topic as solved. Also I can't get rid of this box...

        Ewan Green

        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