Results 1 to 5 of 5

Thread: Stylesheet does not change QToolBar background in QMainWindow

  1. #1
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    77
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Stylesheet does not change QToolBar background in QMainWindow

    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
    Qt Code:
    1. #ifdef Q_OS_LINUX
    2. QApplication::setStyle("Clearlooks");
    3. #endif
    4. #ifdef Q_OS_MACX
    5. QApplication::setStyle("Clearlooks");
    6. #endif
    7. #ifdef Q_OS_WIN32
    8. QApplication::setStyle("Clearlooks");
    9. #endif
    10.  
    11. 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); }");
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheet does not change QToolBar background in QMainWindow

    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

  3. #3
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    77
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheet does not change QToolBar background in QMainWindow

    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.
    Last edited by ad5xj; 11th January 2016 at 19:16.

  4. #4
    Join Date
    Jun 2015
    Location
    California, USA
    Posts
    61
    Thanks
    43
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11

    Default Re: Stylesheet does not change QToolBar background in QMainWindow

    Any gradient I try results in a solid black background for the toolbars.
    However, setting a solid color works as expected.

    Qt Code:
    1. {
    2. background-color: rgb(230, 230, 230);
    3. spacing: 3px;
    4. padding: 4px;
    5. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jun 2007
    Location
    Louisiana
    Posts
    77
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Stylesheet does not change QToolBar background in QMainWindow

    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.

Similar Threads

  1. stylesheet with QAction in QToolBar
    By waiter in forum Qt Programming
    Replies: 2
    Last Post: 4th September 2012, 12:05
  2. How to change the color of background of QMainwindow?
    By weixj2003ld in forum Qt Programming
    Replies: 4
    Last Post: 5th July 2012, 23:56
  3. Replies: 3
    Last Post: 13th November 2011, 08:12
  4. Replies: 2
    Last Post: 21st March 2010, 08:20
  5. QToolBar Stylesheet
    By guilugi in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2007, 11:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.