Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
5.0.0
-
None
Description
Styles that need special fonts for special widgets have two options today:
1) Calling QApplication::setFont(const QFont &font, const char *className)
2) Calling QWidget::setFont() in QStyle::polish(QWidget *)
The problem with #1 is that this applies to the entire application even if the application uses several styles (Designer's preview form, as one example).
The problem with #2 is that it overrides the application and user font settings.
Proposal: Add a protected "QStyle::setFont(const QFont *font, const char *className)" and a public getter "QFont QStyle::font(QWidget *widget) const" that QApplication::font() calls, and the resulting font is resolved against the app font. That way the style can set per-widget fonts (and palettes too!) without disrupting font and palette propagation.
Ideally (Qt 5?) QStyle would have two virtual functions for this instead of a protected setter. And QStyle::polish(QPalette&) would be replaced by the same approach.
Use case: Windows Mobile Style (CE) and QGtkStyle.
Note: Sometimes even more context is needed (than classname) - e.g., for CSS the dependency graph is quite complex so this function would have to be called for each QWidget::paintEvent() / initStyleOption.