[Qt-interest] Stylesheet: some style "specialization" are not taken into account
David Geldreich
david.geldreich at free.fr
Mon May 9 15:45:02 CEST 2011
Hi all,
I am wondering if I am making a mistake, or if it could be a Qt bug.
I had a QToolBar that was customized via a stylesheet. I changed the layout (QLayout vs QSplitter) of my top widget and the spacing/padding for the QToolBar was no longer working.
I made a little example to reproduce the problem.
If I give something like :
QToolBar { background-color: red; spacing: 0px; padding: 0px; }
QToolBar#MainToolbar { background-color: blue; spacing: 20px; padding: 10px;}
I expect the spacing/padding to be overrided for MainToolbar; but this is no longer the case. The entry is taken into account as it s background is blue, only some fields seems to be "ignored".
Changing the spacing/padding of QToolBar is working but not QToolBar#MainToolbar
I am using Qt 4.7.1 (build from sources) on OSX 10.6 and it was also reproduced on Windows Seven
I found nothing similar on http://bugreports.qt.nokia.com.
Thanks in advance.
Here is the complete minimal example to reproduce the problem :
#include <QAction>
#include <QApplication>
#include <QDebug>
#include <QFile>
#include <QSplitter>
#include <QToolBar>
#include <QVBoxLayout>
#include <QWidget>
#include <QWindowsStyle>
int main(int argc, char **argv)
{
QApplication::setStyle(new QWindowsStyle);
QApplication app(argc, argv);
QString cssStr = "QToolButton { background-color: green; }"
"QToolButton:on { color: blue; }"
"QToolBar { background-color: red; spacing: 0px; padding: 0px; }"
"QToolBar#MainToolbar { background-color: blue; spacing: 20px; padding: 10px;}";
app.setStyleSheet(cssStr);
QToolBar *toolbar = new QToolBar;
toolbar->setObjectName("MainToolbar");
QAction *action1 = new QAction("One", toolbar);
action1->setCheckable(true);
QAction *action2= new QAction("Two", toolbar);
action2->setCheckable(true);
QAction *action3 = new QAction("Three", toolbar);
action3->setCheckable(true);
toolbar->addAction(action1);
toolbar->addAction(action2);
toolbar->addAction(action3);
toolbar->show();
qDebug() << toolbar->objectName();
return app.exec();
}
More information about the Qt-interest-old
mailing list