Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsTextItem with ItemIgnoresTransformations causing flickering
Forum Updated to NodeBB v4.3 + New Features

QGraphicsTextItem with ItemIgnoresTransformations causing flickering

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 451 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    publicname123123
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved