PDA

View Full Version : Stylesheet does not change QToolBar background in QMainWindow



ad5xj
10th January 2016, 19:09
I have an application that may run on multiple platforms - Windows, Linux, and Mac.

I am attempting to style a QToolBar in my QMainWindow that remains the same regardless of platform style. My attempts so far are to change the stylesheet option in QDesigner - which did nothing - and specifying a style in the QMainWindow constructor with


#ifdef Q_OS_LINUX
QApplication::setStyle("Clearlooks");
#endif
#ifdef Q_OS_MACX
QApplication::setStyle("Clearlooks");
#endif
#ifdef Q_OS_WIN32
QApplication::setStyle("Clearlooks");
#endif

qApp->setStyle("QToolBar {background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E1E1E1, stop: 0.4 #DDDDDD, stop: 0.5 #D8D8D8, stop: 1.0 #CFCFCF); }");


The only problem is that the only effect is for the toolbar and separator actions to have a dark grey flat background. I can style the QToolButtion but that is the only thing on the toolbar that seems to change as one would expect.

Is there a way to set toolbars with specific stylesheet properties that are the same on all platforms? The aApp->setStyle() does not seem to do it.

What am I missing?

ars
10th January 2016, 20:06
Hello,

some comments: The style is called Cleanlooks and not Clearlooks. If you use Qt5, Cleanlooks is no longer available by default. You have to compile it from the sources and install it to your Qt binaries. For setting the gradient you should use setStyleSheet("...") instead of setStyle(...).

Best regards
ars

ad5xj
11th January 2016, 18:09
My bad. Perhaps that was not a good example for the problem.

The problem is that the QToolBar background needs to be of a type controlled by the stylesheet.

So far I have not been able to change it using ui->mainToolBar::setStyleSheet() either with
"QToolBar {background:...}" or "QToolBar {background-color:...}" or QToolBar {background-image:...}"

The only change is a dark grey background on the toolbar. The QToolButtons on the other hand are completely styled and display as needed with icon and background specified in the stylesheet.

Maybe this is a bug, but I have not found one listed on the bug tracker site like this.

Environment:
Linux Mint 17.3 Cinnamon (32 bit)
Qt 5.5.1

UPDATE: by way of update I have been able to style the toolbar widget using the setStyle(QStyleFactory::create("style"). It will change the base style but the background will still not change.

ravas
17th January 2016, 18:51
Any gradient I try results in a solid black background for the toolbars.
However, setting a solid color works as expected.



QToolBar
{
background-color: rgb(230, 230, 230);
spacing: 3px;
padding: 4px;
}

ad5xj
11th February 2016, 18:19
I have found that you can style toolbutton and toolbar handle with a gradient, but NOT the toolbar background itself.

You can change the background color as long as it is a solid color, but not a gradient.

This appears either a bug or an inconsistent stylesheet methodology between the QToolBar widget and the QToolButton and QToolBar Handle.

It seems as though the widgets placed on a QToolBar do not even inherit much of the style of the QToolBar parent. Not sure if completely re-implementing the QToolBar would work. That is a lot of work for something so simple.

Also, there is no way to stretch a separator or button to fill the width of the QToolBar as you can with the last column in a QTableView or QTableWidget.