I have a QMainWindow with several other widgets contained within it (a QTableView, a QPixmap , a QGroupBox etc.) and I want to be able to change the background color of the parent widget without also changing the background color of its children such as the QTableView so that the window background is a different color, but the background of the table, groupbox, and other widgets beneath it remain with the default look.
Is there any way to do this as currently the children all inherit the backgroundrole of the parent.
I think it's probably unnecessary, but just in case, my current code to change the background color is below:
mainPalette.
setColor(backgroundRole
(),
QColor(1,
2,
3));
setPalette(mainPalette);
setAutoFillBackground(true);
QPalette mainPalette = palette();
mainPalette.setColor(backgroundRole(), QColor(1, 2, 3));
setPalette(mainPalette);
setAutoFillBackground(true);
To copy to clipboard, switch view to plain text mode
Bookmarks