Is there a class or method in Qt to get properties like "border-color", "border-style", ...
This may be usefull to create and paint own (derived) controls based on currently selected style sheets.
Example:
QPushButton {
border: 3px solid red;
background: blue;
margin: 5px;
padding: 10px;
}
The code:
class QPushButtonCircle : public QPushButton {
};
QPushButtonCircle would be a button that is circular. Even the border is circular. The border should 3 pixels width, solid and colored red. The background should be colored blue.
I din't find any way expect drawing entierly in paintEvent and ignoring any style sheets. But there must be a better way.
The best would be something like:
QCssStyle cssStyle = widget->...->getCssStyle();
QPen border = cssStyle->border(QCssStyle::Top);
QBrush background = cssStyle->background();
QMargins margins = cssStyle->margins();
QMargins padding = cssStyle->padding();
...
This would allow us to draw our own controls like in:
QStylePainter p(this);
QRect r = rect();
r.adjust(cssStyle->margins().left(), ...);
p.setPen(cssStyle->border());
p.setBrush(cssStyle->brush());
p.drawEllipse(r);
r.adjust(cssStyle->padding().left(), ...);
p.drawText(r, ...);
A better solution would be a method to draw things like with QStyle::drawControl
, QStyle::drawPrimitive
... but with respecting a QPainterPath (or simpler primitives) instead of assuming rectangular controls.
What is the best way to create owner drawn controls in Qt with derived colors from style sheets?
QString
css property by parsing it with some parser. But without touching the Qt internals it is difficult to handle this: widget'sstylesheet
property is not the complete computed style: parents and qApp also influence. Probably a reason for feature request to Qt devs... – NIA