Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QToolBar background color only applies to actions

I am trying to set the bacground color of a QToolBar in Qt designer with the following in stylesheet background : rgb(30, 30, 30). For some reason the background color is only applied to the action's background as can be seen in the image. How can I change the color of the whole toolbar?

enter image description here

Edit.

Even if I change the background color of my whole window, the area of toolbar is not affected:

enter image description here

This is an empty default Qt widgets application where I only added a QToolBar and one QAction and in the stylesheet of my QMainWindow

background : red;
QToolBar { background : red }
QToolButton {background : red}

Is this expected behaviour or a bug on qt with linux?

edit.

I tried this code on Xubuntu 14.04 with Qt 4.8 and Qt 5.4.2. This seems to be a bug on Qt. See my own answer below.

like image 791
user2563661 Avatar asked Jul 27 '15 09:07

user2563661


2 Answers

Ok, so I did some digging and found this https://forum.qt.io/topic/23800/solved-change-background-color-of-qtoolbar-doesn-t-work-in-linux . Apparently this is a specific problem on some Linux distributions. Adding border: none after the background : rgb(30, 30, 30) fixed the problem. Don't know why my question was downvoted though.

like image 176
user2563661 Avatar answered Sep 20 '22 20:09

user2563661


You can use QT StyleSheet as below :

ui->mainToolBar->setStyleSheet("QToolButton:!hover {background-color:lightgray} QToolBar {background: rgb(30, 30, 30)}");

First color parameter I am setting for ToolBar Button's Background and Second one for Setting color of toolbar Background.

If you want to set only Background color then use StyleSheet as below:

 ui->mainToolBar->setStyleSheet("QToolBar {background: rgb(30, 30, 30)}");

Please check below image for your reference:

enter image description here

I hope you want Toolbar as per above image.

like image 22
Amol Saindane Avatar answered Sep 22 '22 20:09

Amol Saindane