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?
Edit.
Even if I change the background color of my whole window, the area of toolbar is not affected:
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.
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.
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:
I hope you want Toolbar as per above image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With