Removing hardcoded stylesheet changes

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Post Reply
User avatar
chennes
Posts: 1212
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Removing hardcoded stylesheet changes

Post by chennes »

In working with stylesheet authors over the last couple of months, I've run into some calls to setStylesheet() in the source code, often with hardcoded colors and/or margins. Here's the current state (excluding the QSint stuff, which is a whole 'nother deal):

Code: Select all

Gui/DlgMacroExecuteImp.cpp: groupBox7->setStyleSheet(QString::fromLatin1("QGroupBox::title {color:red}"));
Gui/DlgMacroExecuteImp.cpp: buttonAddAction->setStyleSheet(QString::fromLatin1("color:red"));
Gui/DlgMacroExecuteImp.cpp: moveActionRightButton->setStyleSheet(QString::fromLatin1("background-color: red"));
Gui/DlgMacroExecuteImp.cpp: newButton->setStyleSheet(QString::fromLatin1("color:red"));
Gui/DlgMacroExecuteImp.cpp: label->setStyleSheet(QString::fromLatin1("color:red"));
Gui/DlgParameterImp.cpp: ui->findGroupLE->setStyleSheet(QString());
Gui/DlgParameterImp.cpp: ui->findGroupLE->setStyleSheet(styleSheet);
Gui/InputField.cpp: iconLabel->setStyleSheet(QString::fromLatin1("QLabel { border: none; padding: 0px; }"));
Gui/InputField.cpp: setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconLabel->sizeHint().width() + frameWidth + 1));
Gui/MainWindow.cpp: statusBar()->setStyleSheet(QString::fromLatin1("#statusBar{}"));
Gui/MainWindow.cpp: statusBar()->setStyleSheet(d->status->err);
Gui/MainWindow.cpp: statusBar()->setStyleSheet(d->status->wrn);
Gui/MainWindow.cpp: statusBar()->setStyleSheet(QString::fromLatin1("#statusBar{}"));
Gui/MainWindow.cpp: statusBar()->setStyleSheet(d->status->msg);
Gui/SelectionView.cpp: clearButton->setStyleSheet(QString::fromUtf8("QToolButton {margin-bottom:1px}"));
Gui/SpinBox.cpp: lineedit->setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconLabel->sizeHint().width() + frameWidth + 1));
Gui/Widgets.cpp: clearButton->setStyleSheet(QString::fromLatin1("QToolButton { border: none; padding: 0px; }"));
Gui/Widgets.cpp: setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px; } ")
Gui/Widgets.cpp: setStyleSheet(QString::fromLatin1("Gui--UrlLabel {color: #0000FF;text-decoration: underline;}"));
Gui/Widgets.cpp: setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconLabel->sizeHint().width() + frameWidth + 1));
Mod/Arch/ArchAxis.py: self.table.setStyleSheet(style)
Mod/Draft/DraftGui.py: self.baseWidget.setStyleSheet(style)
Mod/Draft/DraftGui.py: self.baseWidget.setStyleSheet(
Mod/Part/Gui/TaskAttacher.cpp: ui->message->setStyleSheet(QString::fromLatin1("QLabel{color: red;}"));
Mod/Part/Gui/TaskAttacher.cpp: ui->message->setStyleSheet(QString());
Mod/Part/Gui/TaskAttacher.cpp: ui->message->setStyleSheet(QString::fromLatin1("QLabel{color: green;}"));
Mod/Part/Gui/TaskAttacher.cpp: ui->message->setStyleSheet(QString::fromLatin1("QLabel{color: red;}"));
Mod/Path/PathScripts/PathGui.py: widget.setStyleSheet("color: black")
Mod/Path/PathScripts/PathGui.py: widget.setStyleSheet("color: gray")
A few of these calls are protected by an if (qApp->styleSheet().isEmpty()) conditional, but most are not. The problem with hardcoded colors is pretty obvious once you get user stylesheets involved. I think the best path for fixing those is to have a set of preferences for those colors, and basically leave the code as-is except swapping in the user-set color choice. This will allow Preference Pack authors to distribute those colors alongside a Qt CSS stylesheet, and won't break any of the code logic that's changing the colors based on some event. Using the conditional there is ineffective because we're using color to represent some state, and to my knowledge that's not something that's available via the globally-loaded stylesheet.

For the padding, it's probably best to use the conditional to guard it. The problem with having it hardcoded is that it's frustrating to stylesheet authors who need to change it, and their changes either have no effect, or have counterintuitive results (e.g. setting the width to some number, and it ends up one higher than that, etc.). This will probably require changes to existing stylesheets, but in many cases those sheets aren't really being maintained and are a bit broken anyway.

Does my suggestion of adding preferences for those colors, and conditionals for the paddings, make sense? Does anyone foresee other problems with that plan?
Chris Hennes
Pioneer Library System
adrianinsaval
Posts: 615
Joined: Thu Apr 05, 2018 5:15 pm

Re: Removing hardcoded stylesheet changes

Post by adrianinsaval »

I can't look closely at any of it right now so I don't know if this gives any issue at all, but I would ask that those that work on this take into account what happens when someone has not set any stylesheet in FreeCAD but has a system wide theme (KDE users like me most likely)
Post Reply