Scroll bar of QTextBrowser loses colors after focussing?
-
I have set the stylesheet of my
QTextBrowser
widget tobackground-color:white
.autoFillBackground
is set totrue
. It is the child widget of aQFrame
and placed in a grid layout so that all but the frame's margin (approx. 2 pixels) is covered. When the text browser has the focus, the background color of theQFrame
is changed to green by setting thestylesheet
property; when it loses focus, it is reset to the normal light-gray color.When the main window containing these widgets is first opened, the scroll bars of the text browser are shown with their normal colors (see screenshot attached:
scroll_bars_normal.png
:But after the browser is focussed once, they turn white, even though I have not changed the stylesheet of the text browser (see screenshot
scroll_bars_after_focus.png
:What is going on here?
-
Hi
And you used the QTextBrowser as selector in the stylesheet and not
QWidget or similar ? -
@mrjj I set the
background-color
for theQFrame widget
(which is the parent of the text browser) when the text browser acquires the focus. But according to the documentation, stylesheets should not propagate to the children, as palettes do (if I understand this correctly, which I probably don't). And the text browser has its own style sheet which also merely hasbackground-color:white;
as the content. -
@mrjj I set the
background-color
for theQFrame widget
(which is the parent of the text browser) when the text browser acquires the focus. But according to the documentation, stylesheets should not propagate to the children, as palettes do (if I understand this correctly, which I probably don't). And the text browser has its own style sheet which also merely hasbackground-color:white;
as the content.@Robert-Hairgrove
Oh but stylesheets do propagate.
If the selector matches, then any children will be affected.
Just try
QWidget {
background-color:white;
}
on a parent and all children will be colored. -
@Robert-Hairgrove
Oh but stylesheets do propagate.
If the selector matches, then any children will be affected.
Just try
QWidget {
background-color:white;
}
on a parent and all children will be colored.@mrjj Thank you, this is stated very clearly at the top of the documentation about "Qt Style Sheets", but I seem to have overlooked it.
The problem was that I had set some things in Qt Designer and weird things were happening with the palettes as well. So I deleted all of the style sheets I had set and made sure that the
palette
properties all said "inherited".Now everything is working properly!
-
Hi
Super.
Often one stylesheet is used and only set on the application.
So it affects all it children and much easier to manage as its just one sheet.
Mixing palette and stylesheet can also sometimes do strange stuff.
At least it did for me.