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. QPainter reset Transformation Does not work.
Qt 6.11 is out! See what's new in the release blog

QPainter reset Transformation Does not work.

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

    Dear All,

    I am having a QgraphicsItem on top of that I am drawing a text. Now I am rotating the graphics item but i don't want to rotate the text. So I am resetting the QPainter using reset transform method. But when I am applying the reset transform even my text is not painting by the painter.
    I am giving the sample code.
    I want to achieve that transformation should apply to graphics item but not on the text.

     painter->resetTransform();
        qreal width = boundingRect().width();
        qreal height = boundingRect().height();
    
            
        QFont font = painter->font();
        font.setFamily(QString("Courier New"));
        font.setBold(true);
        font.setPointSize(boundingRect().width());
        painter->setFont(font);
    
        float widthFactor = boundingRect().width() / painter->fontMetrics().boundingRect(text).width();
        float heightFactor = boundingRect().height() / painter->fontMetrics().boundingRect(text).height();
    
        if(widthFactor > heightFactor)
            widthFactor = heightFactor;
    
        if((widthFactor < 1)  || (widthFactor > 1.25))
        {
            font.setPointSizeF(font.pointSizeF()*widthFactor);
            painter->setFont(font);
        }
    
        painter->drawText(boundingRect().x(), boundingRect().y(), width, height, Qt::AlignCenter,text);
    

    TIA

    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