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. Maintaining text position after applying ItemIgnoresTransformations flag in Qt
Forum Updated to NodeBB v4.3 + New Features

Maintaining text position after applying ItemIgnoresTransformations flag in Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 177 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.
  • T Offline
    T Offline
    tushu
    wrote on last edited by tushu
    #1

    I am having QGraphicsView, which has multiple QGraphicsItem's. On QGraphicsView I am performing multiple transformation like zoom-in, zoom-out, Fit-in etc. In QGraphicsItem, I am having few rectangles and some polylines Every polyline has its own name written above it.
    Whenever I zoom-in or zoom-out my view, I dont want to change my text size. It should remain same. For that I applied flag QGraphicsItem::ItemIgnoresTransformations.
    But after applying this flag, whenever I zoomed-in text changes its position. Means in every zoom-in it should be just above the polyline. But it is changing it's position.

    myText.cpp

    myText::myText(const QString &text): QGraphicsSimpleTextItem(text)
    {}    
            
    QRectF myText::boundingRect() const
    {
       QRectF b = QGraphicsSimpleTextItem::boundingRect();
        return QRectF(b.x()-b.width()/2.0, b.y()-b.height()/2.0,
                      b.width(), b.height());
    }        
           
    void myText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    {
        painter->translate(boundingRect().topLeft());
        QGraphicsSimpleTextItem::paint(painter, option, widget);
        painter->translate(-boundingRect().topLeft());
    }
    

    myClass.cpp

    void myClass:: addText()
    {
         QGraphicsSimpleTextItem* text= new QGraphicsSimpleTextItem("Line 1");
         text->setPos(QPointF(some points );
         text->setDefaultTextColor(Qt::black);
         text->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
         scene->addItem(text);
    }
    

    So question is :
    How to ensure that text should not change its position ?

    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