View Full Version : styling parent but not child?
ugluk
10th October 2011, 11:36
Is it possible to style the parent of a widget, but prevent child widgets from inheriting the parent's style?
Say I have a QListView, which can have 2 scrollbars. If I set the background style of the QListView to say, background:red, the scrollbars will likewise color red, but I'd like them to assume the system default color.
ugluk
10th October 2011, 13:49
My current solution is this:
- setAttribute(Qt::WA_NoSystemBackground) on the view,
- override view's paintEvent() and repaint the background manually, but differently for the "main" area and the areas of the scrollbars, if they are visible.
wysota
10th October 2011, 13:53
Say I have a QListView, which can have 2 scrollbars. If I set the background style of the QListView to say, background:red, the scrollbars will likewise color red, but I'd like them to assume the system default color.
QPalette p = view->palette();
p.setColor(QPalette::Base, Qt::red);
view->setPalette(p);
ugluk
13th October 2011, 02:55
It works! Thanks!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.