How to stylize custom Qt widgets globally?

58 views Asked by At

I have custom widgets which inherit QWidget.

I'm trying to use the palette, style, and font of the widgets as much as possible, and implement QWidget::changeEvent(), to keep their look consistent with the current style.

However, sometimes a widget needs more styling than just what QStyle and QPalette provide.

Examples for me are:

  • The colors of some success, warning, and error sections.
  • The font to use for monospace text.

I'd like those to be global, not specified for each widget instance.

I can't find a natural Qt approach to this problem.

My current solution is for those custom widgets to know the specific style class of the application (casting the application style to QMyStyle&, for example), but this coupling removes their portability.

How does one make a reusable QWidget which needs custom color roles and fonts?

NOTE: I don't want to use style sheets because it has its share of problems, some of which I encountered.

0

There are 0 answers