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. Scaling QPainter transform
Forum Updated to NodeBB v4.3 + New Features

Scaling QPainter transform

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 512 Views 1 Watching
  • 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.
  • L Offline
    L Offline
    LostBoy
    wrote on last edited by LostBoy
    #1

    I'm tring to edit the 40000 chip demo demo (for learning purposes), so the text on the chips doesn't scale when i zoom in/out. I have edited the code of chip.cpp like this:

     // Draw text
        if (lod >= 4) {
            QFont font("Times", 10);
            font.setStyleStrategy(QFont::ForceOutline);
    
            painter->setFont(font);
            painter->save();
            QTransform transform = painter->transform();
            transform.setMatrix(1,transform.m12(), transform.m13(), transform.m21(), 1, transform.m23(), transform.m31(), transform.m32(), transform.m33());
    
            painter->setWorldTransform(transform);
    
            painter->drawText(170, 180, QString("Model: VSC-2000 (Very Small Chip) at %1x%2").arg(x).arg(y));
            painter->drawText(170, 200, QString("Serial number: DLWR-WEER-123L-ZZ33-SDSJ"));
            painter->drawText(170, 220, QString("Manufacturer: Chip Manufacturer"));
            painter->restore();
        }
    }
    

    I've set the scale of the QPainter's transform to 1, however i'm getting weird results. Text appears to move away from the chips when i zoom out or rotate the view:
    chips.PNG
    What I am doing wrong?

    kshegunovK 1 Reply Last reply
    0
    • L LostBoy

      I'm tring to edit the 40000 chip demo demo (for learning purposes), so the text on the chips doesn't scale when i zoom in/out. I have edited the code of chip.cpp like this:

       // Draw text
          if (lod >= 4) {
              QFont font("Times", 10);
              font.setStyleStrategy(QFont::ForceOutline);
      
              painter->setFont(font);
              painter->save();
              QTransform transform = painter->transform();
              transform.setMatrix(1,transform.m12(), transform.m13(), transform.m21(), 1, transform.m23(), transform.m31(), transform.m32(), transform.m33());
      
              painter->setWorldTransform(transform);
      
              painter->drawText(170, 180, QString("Model: VSC-2000 (Very Small Chip) at %1x%2").arg(x).arg(y));
              painter->drawText(170, 200, QString("Serial number: DLWR-WEER-123L-ZZ33-SDSJ"));
              painter->drawText(170, 220, QString("Manufacturer: Chip Manufacturer"));
              painter->restore();
          }
      }
      

      I've set the scale of the QPainter's transform to 1, however i'm getting weird results. Text appears to move away from the chips when i zoom out or rotate the view:
      chips.PNG
      What I am doing wrong?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @LostBoy said in Scaling QPainter transform:

      What I am doing wrong?

      The diagonal elements are important both for the scale and the rotate transformation. Try using transform.scale() instead. Qt should be able to do the right thing. If the operations are not kept separate internally, however, i.e. the whole transform is kept as a single matrix, then the separate components can't be recreated back from the transformation matrix.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2

      • Login

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