I'm trying to apply a stylesheet on my Qt user interface. It works fine on elements such as QTreeWidget, QToolBar, QToolButton, etc. It also applies on QScrollBars on designer preview, but when I run the application, scrollbars are drawn like native Ubunut's/Windows' style scrollbars disregarding my designed style. It happens both in Ubuntu in Gnome-Shell, in xinit (without any window manager) and Windows 7.

What's the problem?

有帮助吗?

解决方案

Well, I was selecting the QScrollBar with a combination of ID-Selectors and Descendant-Selectors like this:

QTreeWidget#list QScrollBar:vertical {

It worked well in qt designer as supposed to. But something that seems like a bug made it not work in runtime because in runtime Qt decides that my scrollbar is not child of my treewidget anymore and it recognizes the scrollbar as a child of the parent of the treewidget which makes it a sibling of the treewidget (at least its stylesheet manager does so). So selecting it somehow like this:

QScrollBar:vertical {
#centralWidget QScrollBar:vertical {  // Where centralWidget is the parent of the treewidget

solved the problem.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top