Unsolved QGraphicsTextItem with ItemIgnoresTransformations causing flickering
-
Hi. Been trying to use QGraphicsTextItem with QGraphicsItem::ItemIgnoresTransformations. First ran into a problem where the text items "slid" on zooming (relative to other graphic items, which did not ignore transformations). This was due to the origin point being the top left corner, instead of the midpoint. This was overcome with this simple wrapper class:
struct TextItem : public QGraphicsTextItem { TextItem (const QString &text) : QGraphicsTextItem(text) {} void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { const auto rect = boundingRect(); painter->save(); painter->translate(-rect.width() / 2.0, -rect.height() / 2.0); QGraphicsTextItem::paint(painter, option, widget); painter->restore(); } };
The issue now is "flickering" (parts of the text being hidden) when a different graphics item is dragged across the text items. Anything obvious that I am doing wrong?
Note: The save/restore calls don't actually seem to make a difference based on some of my testing.