border-color property does not work on custom stylesheet
-
From here I learn I can customize a
QLineEdit
(but I guess any widget that supports the box model) using theborder-color
property.In my Qt 6.8.2 desktop application I have this code:
if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) { w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }"); }
The goal is to apply the stylesheet to all widgets at once.
Actually thegridline-color
is honored, but theborder-color
does not:As you can see the grid of the
QTableView
is grady (instead of the default black) but theQLineEdit
border is still black.
Is my stylesheet wrong?Here the content of my
main.cpp
:#include "mainwindow.h" #include <QStyleHints> #include <QApplication> #include <QDebug> int main(int argc, char *argv[]) { QApplication a(argc, argv); QCoreApplication::setApplicationVersion("v0.1"); MainWindow w; // QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light); <--- this does not work either if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) { w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }"); } w.show(); return a.exec(); }
-
From here I learn I can customize a
QLineEdit
(but I guess any widget that supports the box model) using theborder-color
property.In my Qt 6.8.2 desktop application I have this code:
if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) { w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }"); }
The goal is to apply the stylesheet to all widgets at once.
Actually thegridline-color
is honored, but theborder-color
does not:As you can see the grid of the
QTableView
is grady (instead of the default black) but theQLineEdit
border is still black.
Is my stylesheet wrong?Here the content of my
main.cpp
:#include "mainwindow.h" #include <QStyleHints> #include <QApplication> #include <QDebug> int main(int argc, char *argv[]) { QApplication a(argc, argv); QCoreApplication::setApplicationVersion("v0.1"); MainWindow w; // QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light); <--- this does not work either if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) { w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }"); } w.show(); return a.exec(); }
-
From here I learn I can customize a
QLineEdit
(but I guess any widget that supports the box model) using theborder-color
property.In my Qt 6.8.2 desktop application I have this code:
if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) { w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }"); }
The goal is to apply the stylesheet to all widgets at once.
Actually thegridline-color
is honored, but theborder-color
does not:As you can see the grid of the
QTableView
is grady (instead of the default black) but theQLineEdit
border is still black.
Is my stylesheet wrong?Here the content of my
main.cpp
:#include "mainwindow.h" #include <QStyleHints> #include <QApplication> #include <QDebug> int main(int argc, char *argv[]) { QApplication a(argc, argv); QCoreApplication::setApplicationVersion("v0.1"); MainWindow w; // QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light); <--- this does not work either if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) { w.setStyleSheet("* { gridline-color: dimgray; border-color: red; }"); } w.show(); return a.exec(); }
-
@Mark81 You need to write the full border style:
border-width: 1px; border-style: solid; border-color: red;
or
border: 1px solid red
@Bonnie said in border-color property does not work on custom stylesheet:
@Mark81 You need to write the full border style:
You're right. I didn't understand this from the docs!
Out of curiosity, to test the
Light
style I added this line:QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Light);
but the theme is still dark (as per my system settings).
The docs (here) state I can set an explicit color scheme. Is there anything else I should set?I'm aware it is slightly offtopic, but it is useful to test the stylesheet in different scenarios.