Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Scale QPainter so that it keeps my drawing coordination
Qt 6.12 LTS is out! See what's new in the release blog

Scale QPainter so that it keeps my drawing coordination

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

    I have a QLabel that I set an image QPixmap to it and I want to draw some points on the image.The image label has

    m_imageLabel->setScaledContents(true);
    

    so that when I change the window the point should scale also.
    I try to keep the original point coordination rescaling the painter :

    // Calculate the size keeping ratio image with zoom factor
    //this is call in qlabel paint event 
      QSize sizeWithRatio(m_imageWidth, m_imageHeight); // original photo size 
      sizeWithRatio.scale(width() - 10, height() - 10, Qt::KeepAspectRatio);
      qreal resizeRatioH = sizeWithRatio.height() / (qreal)m_imageHeight;
      qreal resizeRatioW = sizeWithRatio.width() / (qreal)m_imageWidth;
      QPainter painterImage(this);
      painterImage.scale(resizeRatioW, resizeRatioH);
      painterImage.setRenderHint(QPainter::Antialiasing);
    

    24534a3f-d3dc-4ebf-acd9-9578c52d40ee-image.png

    What I want is to keep the point in same place if I resize the window

    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
    • Unsolved