Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved How do I scale an image with QPainter?

    General and Desktop
    qpainter
    2
    3
    1078
    Loading More Posts
    • 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
      lansing last edited by

      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 Reply Quote 0
      • B
        Bonnie last edited by 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 1 Reply Last reply Reply Quote 3
        • L
          lansing @Bonnie last edited by

          @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 Reply Quote 0
          • First post
            Last post