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. How do I scale an image with QPainter?

How do I scale an image with QPainter?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpainter
3 Posts 2 Posters 2.6k 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.
  • L Offline
    L Offline
    lansing
    wrote on last edited by
    #1

    I have an image stored as QPixmap and I want to draw it out with QPainter and scale it. I overloaded the QPaintEvent in my widget and drew the QPixmap, but I don't know how to get it to scale.

    void ImagePainter::paintEvent(QPaintEvent *a_pEvent)
    {
        QPainter painter(this);
        painter.drawPixmap(10,10, m_image.width(), m_image.height(), m_image);
        painter.scale(1000,800);
        painter.end();    
    }
    

    The scale function in here didn't do anything.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      Scale first, then draw. Or you could also just do like

      painter.drawPixmap(10,10, m_image.width() * 1000, m_image.height() * 800, m_image);
      

      You may also call painter.setRenderHint(QPainter::SmoothPixmapTransform) before drawing any pixmap to make it scales more smoothly.

      L 1 Reply Last reply
      3
      • B Bonnie

        Scale first, then draw. Or you could also just do like

        painter.drawPixmap(10,10, m_image.width() * 1000, m_image.height() * 800, m_image);
        

        You may also call painter.setRenderHint(QPainter::SmoothPixmapTransform) before drawing any pixmap to make it scales more smoothly.

        L Offline
        L Offline
        lansing
        wrote on last edited by
        #3

        @Bonnie

        Thank you, setting it before drawPixmap works. I don't need any smoothing so nearest neighbor resize is fine for me.

        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