Changine Palette to Dark, doesn´t change everything.
-
Hi there..
I managed to change my Color Palette at runtime, with simply changing the QPalette.'But i think, there are some Widgets Missing in the ColorRoles. For example:
Menubar, Toolbar, Tabmenu, scrollArea, Scrollbars...and a few moreCause those Widget won´t get color changed, like the rest.
These are the Palettes:
QPalette darkPalette; QPalette lightPalette = QStyleFactory::create("fusion")->standardPalette(); darkPalette.setColor(QPalette::Window, QColor(53, 53, 53)); darkPalette.setColor(QPalette::WindowText, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::WindowText,QColor(127, 127, 127)); darkPalette.setColor(QPalette::Base, QColor(42, 42, 42)); darkPalette.setColor(QPalette::AlternateBase, QColor(66, 66, 66)); darkPalette.setColor(QPalette::ToolTipBase, Qt::white); darkPalette.setColor(QPalette::ToolTipText, QColor(53, 53, 53)); darkPalette.setColor(QPalette::Text, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127)); darkPalette.setColor(QPalette::Dark, QColor(35, 35, 35)); darkPalette.setColor(QPalette::Shadow, QColor(20, 20, 20)); darkPalette.setColor(QPalette::Button, QColor(53, 53, 53)); darkPalette.setColor(QPalette::ButtonText, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText,QColor(127, 127, 127)); darkPalette.setColor(QPalette::BrightText, Qt::red); darkPalette.setColor(QPalette::Link, QColor(42, 130, 218)); darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218)); darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80)); darkPalette.setColor(QPalette::HighlightedText, Qt::white); darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText,QColor(127, 127, 127));
Is there something missing?
-
Qt is using platform specific
QStyle
s. These try to mimic the normal appearances of the according OSes. Unfortunately, this means that not everything usesQPalette
entries. I guess what would work best is the "Fusion" style. However, it does not look normal on Windows and Mac. You could tweak styles using aQProxyStyle
to just change certain things without reimplementing the whole style.That being said: We use tweaked
QPalette
plus stylesheets for the rest. This works great.@BDC_Patrick said in Changine Palette to Dark, doesn´t change everything.:
ui->toolBar->setStyleSheet("#toolBar {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop:0 rgba(0,0,0,255), stop:0.5 rgba(55,55,55,255))}");
Does your Toolbar have a property
toolBar
? Normally, you would set the stylesheet forQToolBar
:ui->toolBar->setStyleSheet("QToolBar {...}");
-
My personal experience (definitely not a "canonical answer") is that Qt widgets better support CSS like modification than palette tweaking. See e.g. https://doc.qt.io/qt-5/stylesheet-reference.html as a starting point.
-
Thanks.. but.. how?
F.e.:
ui->toolBar->setPalette(darkPalette); ui->toolBar->setStyleSheet("#toolBar {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop:0 rgba(0,0,0,255), stop:0.5 rgba(55,55,55,255))}");
i added the dark Palette to my Toolbar, so it changes dark, too.
Now i want to apply a gradient effect... Same way, i do recoloring of the background colors of other widgets..
But for toolbar, it is not working..
And it doesn´t matter if i use
background or backgound-color, toolbar or QToolBar.. or if i use #hex color or rgba..
One time, it doesn´t affect anything.. second time.. it shows only black..
The toolbar won´t get a gradient T_T -
Not exactly what you ask for but you could try a border-image https://doc.qt.io/qt-5/stylesheet-reference.html#border-image
ui->mainToolBar->setStyleSheet("border-image: url(:/ic/res/GradientImage.JPG)");
worked reasonably well on my system (ubuntu, Qt 5.7 - I know, ages old)
-
Qt is using platform specific
QStyle
s. These try to mimic the normal appearances of the according OSes. Unfortunately, this means that not everything usesQPalette
entries. I guess what would work best is the "Fusion" style. However, it does not look normal on Windows and Mac. You could tweak styles using aQProxyStyle
to just change certain things without reimplementing the whole style.That being said: We use tweaked
QPalette
plus stylesheets for the rest. This works great.@BDC_Patrick said in Changine Palette to Dark, doesn´t change everything.:
ui->toolBar->setStyleSheet("#toolBar {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop:0 rgba(0,0,0,255), stop:0.5 rgba(55,55,55,255))}");
Does your Toolbar have a property
toolBar
? Normally, you would set the stylesheet forQToolBar
:ui->toolBar->setStyleSheet("QToolBar {...}");
-
Qt is using platform specific
QStyle
s. These try to mimic the normal appearances of the according OSes. Unfortunately, this means that not everything usesQPalette
entries. I guess what would work best is the "Fusion" style. However, it does not look normal on Windows and Mac. You could tweak styles using aQProxyStyle
to just change certain things without reimplementing the whole style.That being said: We use tweaked
QPalette
plus stylesheets for the rest. This works great.@BDC_Patrick said in Changine Palette to Dark, doesn´t change everything.:
ui->toolBar->setStyleSheet("#toolBar {background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop:0 rgba(0,0,0,255), stop:0.5 rgba(55,55,55,255))}");
Does your Toolbar have a property
toolBar
? Normally, you would set the stylesheet forQToolBar
:ui->toolBar->setStyleSheet("QToolBar {...}");
@SimonSchroeder Thanks..
I think I'll give myself a full qss push.. -
@SimonSchroeder Thanks..
I think I'll give myself a full qss push..If your
QToolBar
's name is toolBar and you want to change only this specific toolbar, then it would be("QToolBar#toolBar { . . . } ");