Custom QTableView Stylesheet
-
I am using Qt 5.15. My application allows the user to switch between 3 different themes (none, dark, and light). When switching between themes one of my custom QTableViews stops using the selected stylesheet. This only happens when switching; upon application startup, it retains the proper last used theme's stylesheet. Other QTreeViews and/or QTableViews used in the application do not have this issue.
Sample stylesheet contains:
QAbstractItemView { background-color: #414147; alternate-background-color: #545459; }
Even explicitly using:
CustomTableView { background-color: #414147; alternate-background-color: #545459; }
will still resort to the same odd behavior. Any suggestions on what I can look for to determine why the custom QTableView doesn't behave like the others?
-
Two things. First check if QEvent::StyleChange is sent to your custom widget. Second see if it works when you explicitly call qApp->polish(customWidgetPtr) after you set the new app style.
-
Thanks for the info.
There are times when QEvent::StyleChange was not received and of course the stylesheet was not correctly applied. But there were also times when it was received but the custom table view still ignored the stylesheet. (I printed the stylesheet each time the event was received.)
I wasn't sure where I was supposed to make the polish call so I didn't get any additional information from this.Sometimes it's the rows that are not following the stylesheet and sometime it's the header that is not following the stylesheet. It is not consistent.
Here's the table when there's no stylesheet selected.
Here the table ignored the background color and text color of the row it should be black with white text but the header section is correct.
Here the table ignored the background color of the row (it should be yellow) and the header section is correct.
Here the background color and text color of the row are correct but the header section is incorrect, the header section should be black with white text.
Here the background color and text color of the row are correct but the header section is incorrect, the header section should be yellow with black text.