Set base stylesheet settings

This commit is contained in:
manongjohn 2022-04-30 10:33:54 -04:00
parent a05b3e7fb2
commit 2fbeb9af0f
7 changed files with 31 additions and 35 deletions

View file

@ -310,7 +310,6 @@ QMenu {
}
QMenu::item {
border: 0;
padding: 3 28 3 8;
}
QMenu::item:selected {
background-color: #a35293;

View file

@ -310,7 +310,6 @@ QMenu {
}
QMenu::item {
border: 0;
padding: 3 28 3 8;
}
QMenu::item:selected {
background-color: #a35293;

View file

@ -310,7 +310,6 @@ QMenu {
}
QMenu::item {
border: 0;
padding: 3 28 3 8;
}
QMenu::item:selected {
background-color: #d97fbe;

View file

@ -310,7 +310,6 @@ QMenu {
}
QMenu::item {
border: 0;
padding: 3 28 3 8;
}
QMenu::item:selected {
background-color: #a35293;

View file

@ -140,7 +140,6 @@ QMenu {
padding: 2 0;
&::item {
border: 0;
padding: 3 28 3 8;
&:selected {
background-color: @menu-item-bg-color-selected;
color: @menu-item-text-color-selected;

View file

@ -310,7 +310,6 @@ QMenu {
}
QMenu::item {
border: 0;
padding: 3 28 3 8;
}
QMenu::item:selected {
background-color: #c16099;

View file

@ -402,26 +402,7 @@ void Preferences::definePreferenceItems() {
// Interface
define(CurrentStyleSheetName, "CurrentStyleSheetName", QMetaType::QString,
"Dark");
// Qt has a bug in recent versions that Menu item Does not show correctly
// (QTBUG-90242) Since the current OT is made to handle such issue, so we need
// to apply an extra adjustment when it is run on the older versions (5.9.x)
// of Qt
// Update: confirmed that the bug does not appear at least in Qt 5.12.8
QString defaultAditionalSheet = "";
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 9)
defaultAditionalSheet = "QMenu::Item{ padding: 3 28 3 28; }";
#endif
// Linux system font size appears a lot smaller than it should be despite
// setting QApplication's setPixelSize = 12 in main.cpp. We'll correct it using
// the additional stylesheet.
#if defined(LINUX) || defined(FREEBSD)
defaultAditionalSheet = "QWidget { font: 12px; }" + defaultAditionalSheet;
#endif
define(additionalStyleSheet, "additionalStyleSheet", QMetaType::QString,
defaultAditionalSheet);
define(additionalStyleSheet, "additionalStyleSheet", QMetaType::QString, "");
define(iconTheme, "iconTheme", QMetaType::Bool, false);
define(pixelsOnly, "pixelsOnly", QMetaType::Bool, true);
define(oldUnits, "oldUnits", QMetaType::QString, "mm");
@ -1022,20 +1003,41 @@ QString Preferences::getCurrentStyleSheet() const {
currentStyleSheetName + QString(".qss");
QString styleSheetPath = path.getQString() + "/" + string;
QString additionalSheetStr = getStringValue(additionalStyleSheet);
// if there is no additional style sheet, return the path and let
// Qt to load and parse it
if (additionalSheetStr.isEmpty()) return QString("file:///" + styleSheetPath);
// Set base stylesheet settings. This is used to correct QT styling
// issues between different versions/OSes. Stylesheets and Additional
// stylesheets can override these settings.
QString baseSheetStr = "";
// if there is any additional style sheet, load the style sheet
// from the file and combine with it
QString styleSheetStr;
// Qt has a bug in recent versions that Menu item Does not show correctly
// (QTBUG-90242) Since the current OT is made to handle such issue, so we need
// to apply an extra adjustment when it is run on the older versions (5.9.x)
// of Qt
// Update: confirmed that the bug does not appear at least in Qt 5.12.8
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 9)
baseSheetStr += "QMenu::Item{ padding: 3 28 3 28; }";
#else
baseSheetStr += "QMenu::Item{ padding: 3 28 3 8; }";
#endif
// Linux system font size appears a lot smaller than it should be despite
// setting QApplication's setPixelSize = 12 in main.cpp. We'll correct it using
// the additional stylesheet.
#if defined(LINUX) || defined(FREEBSD)
baseSheetStr += "QWidget{ font: 12px; }QToolTip{ font: 12px; }";
#endif
QString styleSheetStr = baseSheetStr;
// Load style sheet from the file and add to base style sheet
QFile f(styleSheetPath);
if (f.open(QFile::ReadOnly | QFile::Text)) {
QTextStream ts(&f);
styleSheetStr = ts.readAll();
styleSheetStr += ts.readAll();
}
styleSheetStr += additionalSheetStr;
// If there is any additional style sheet, append to loaded stylesheet
styleSheetStr += getStringValue(additionalStyleSheet);
// here we will convert all relative paths to absolute paths
// or Qt will look for images relative to the current working directory