Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

c++ - Stylesheet on QScrollBar leaves background of scrollbar with checkerboard pattern?

When I style my QScrollBar using a stylesheet, the background color is checkered instead of being solid.

QScrollBar:horizontal {
    background-color: grey;
}

enter image description here

How do you make the background of the scrollbar a solid color?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

What you are referring to as "the background" is actually the two sub-elements add-page and sub-page. You need to define the background element on those sub-elements.

The simplest solution would be to remove the background on both. Then it would inherit the background color grey that you have already set on QScrollBar:

QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {
    background: none;
}

enter image description here

But if desired, you could style each individually to your liking:

QScrollBar::sub-page:horizontal {
    background: red;
}

QScrollBar::add-page:horizontal {
    background: green;
}

enter image description here

Source.

Unfortunately, this solution is rather hard to divine from the official documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...