[Interest] Retrieving view scale factor when painting a QGraphicsItem in Qt 6

Nyall Dawson nyall.dawson at gmail.com
Mon Mar 29 06:28:06 CEST 2021


Hi list,

While attempting to port an application to Qt 6, I've hit a dead end.
In the Qt 5 code we use the QStyleOptionGraphicsItem::matrix value in
the paint override in order to determine the current view scaling, and
then generate images using the corresponding dpi. We do this to avoid
unnecessary work -- if the view is scaled out to 50%, then it's
pointless generating the images at the same number of pixels as when
the view is scaled to 100%.

Now, in qt 6 QStyleOptionGraphicsItem::matrix has been removed, and I
am struggling to find any alternative approach to handling this
situation. There's horrible hacks you can do where you could retrieve
views using QGraphicsScene::views(), but that method only works if a
scene is used in a single view... because otherwise you still have no
way of knowing from QGraphicsItem::paint exactly WHICH view the item
is currently being painted for.

(I can't use the "widget" argument of QGraphicsItem::paint because a
QGraphicsEffect is set for the item, so the widget argument is always
a nullptr value).

How can this situation be handled in Qt 6?

Nyall


More information about the Interest mailing list