Make an element look active when it loses focus
-
Hi, do you know how can I make an element look active when it loses focus?
I have a
QTreeWidgetand I need the selection to look blue even though I have gone to another application. My app has fusion style.

I tried to change stylesheet but the left triangle and the color... :

I'd rather do it differently.
Maybe it could somehow make the widget not lose focus, or at least make it appear not to lose focus? -
Hi
Its not possible to make it not lose focus when switching to another app.Can i ask why its so important to you that your app does not follow the normal visual guidelines?
Its by design the selection color is grey when not having focus. -
Hi
Its not possible to make it not lose focus when switching to another app.Can i ask why its so important to you that your app does not follow the normal visual guidelines?
Its by design the selection color is grey when not having focus.It is a program that I am going to use on a second screen while I have the focus on another app.
I am going to make the selection in the Qt app with global hotkeys while I am using another application and I wanted to see the selection in blue like when I use the app normally but of course, the app does not have the focus and it looks gray.
-
Hi
Ok that way.
Well on Windows the fusion style seems not to use palette so the old trickQPalette p = palette(); p.setColor(QPalette::Inactive, QPalette::Highlight, p.color(QPalette::Active, QPalette::Highlight)); setPalette(p);Seems to have no effect.
I also tried with a QStyledItemDelegate but i cant tell where it get that blue
selection color from with Fusion as it it seems to ignore all palette.
https://code.woboq.org/qt5/qtbase/src/widgets/styles/qfusionstyle.cpp.htmlSo I think your best bet is the stylesheet even if not perfect.
-
Hi
Ok that way.
Well on Windows the fusion style seems not to use palette so the old trickQPalette p = palette(); p.setColor(QPalette::Inactive, QPalette::Highlight, p.color(QPalette::Active, QPalette::Highlight)); setPalette(p);Seems to have no effect.
I also tried with a QStyledItemDelegate but i cant tell where it get that blue
selection color from with Fusion as it it seems to ignore all palette.
https://code.woboq.org/qt5/qtbase/src/widgets/styles/qfusionstyle.cpp.htmlSo I think your best bet is the stylesheet even if not perfect.
@mrjj it worked!
I'm using PySide2
palette = self.palette() palette.setColor(QtGui.QPalette.Inactive, QtGui.QPalette.Highlight, palette.color(QtGui.QPalette.Active, QtGui.QPalette.Highlight)) palette.setColor(QtGui.QPalette.Inactive, QtGui.QPalette.HighlightedText, palette.color(QtGui.QPalette.Active, tGui.QPalette.HighlightedText)) self.setPalette(palette)Thanks!
-
@mrjj it worked!
I'm using PySide2
palette = self.palette() palette.setColor(QtGui.QPalette.Inactive, QtGui.QPalette.Highlight, palette.color(QtGui.QPalette.Active, QtGui.QPalette.Highlight)) palette.setColor(QtGui.QPalette.Inactive, QtGui.QPalette.HighlightedText, palette.color(QtGui.QPalette.Active, tGui.QPalette.HighlightedText)) self.setPalette(palette)Thanks!
-
@Flanagan
Oh so on your platform, it did allow to color the inactive as active?
Cool. Thank for reporting back.Ps. What platform ? linux or also windows ?
-
@mrjj Yep, I'm using Windows, it works even the other way, Active to Inactive
Video proof:
https://mega.nz/file/OlwCjKCZ#fcPYipywn2_XcOfV4Ai3zytRMz1f8InCiMNs4H5UcX8 -
@Flanagan
Ok thats odd i could not get it to do it on win 10 . :)
Im using Qt 15.0
What version does this work in ?
In any case, im happy it still worked. -
@mrjj I use Windows 10 and PySide2 5.15.
https://www.qt.io/blog/qt-for-python-5.15.0-is-outxD it's odd that it doesn't work for you.