Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set global QPainter default render hints?

When a QPainter is created, it has some default render hints. Some widgets override them when painting themselves. Is it possible to override these defaults and disable the per-widget overrides for the entire application?

I'd like to override the defaults as follows, and make all widget classes follow these:

painter->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing, false);
painter->setRenderHints(QPainter::TextAntialiasing , true);

Is it possible?

UPDATE:

Short answer: not possible without changing Qt source code.

like image 510
synacker Avatar asked Jan 19 '26 22:01

synacker


1 Answers

Unfortunately, Qt doesn't implement any public way of doing this.

There are two issues:

  1. The default render hint - QPainter::TextAntialiasing is set in QPainter::begin(QPaintDevice*). This is exactly what you wanted according to your question, but

  2. The widgets are free to override these defaults. And many of them do. There is no way to disable that, without inserting a shim paint engine (or similar) that would intercept these and ignore them.

The simplest way to change it is to modify the QPainter::setRenderHint and QPainter::setRenderHints to disable the overrides on certain widget types, and rebuild Qt. In any professional setting you'll be using your own build of Qt anyway, so that shouldn't be an issue.

There probably is a way of hooking it using Qt's private headers, most likely by offering a shim paint engine and swapping it out on the backing store, without modifying Qt itself, but it'll be messy and not worth it.

like image 120
Kuba hasn't forgotten Monica Avatar answered Jan 21 '26 12:01

Kuba hasn't forgotten Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!