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. Paint Event and Zoomed In Image Problem
Forum Update on Monday, May 27th 2025

Paint Event and Zoomed In Image Problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
paint eventpainterzoomsizeqlabel
4 Posts 2 Posters 1.2k 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.
  • N Offline
    N Offline
    Nalu323
    wrote on 4 Feb 2019, 16:44 last edited by Nalu323 2 Apr 2019, 16:49
    #1

    Hi, I'm working on a project where I have to do an image editor similar to Paint. I would like to open up an image, zoom in/zoom out if necessary, and then draw on it. For that, I used Image Viewer and Scribble examples, and created a QLabel subclass that is supposed to draw lines and other forms with the mouse button.
    The problem is, when I open my image, I'm able to zoom on it normally:
    0_1549298361709_1a1dabe8-82f3-452d-bc38-8b7149c3839f-image.png

    But when I want to draw something it resizes the image to it's original size, but keeps labels zommed in's size:

    0_1549298507379_e48db041-3d6b-40a6-87b1-f1f87f5e4b57-image.png

    I believe that it has something to do with the overriden paintEvent that I use to draw, here's it's code:

    void imLabel::paintEvent(QPaintEvent *event){
        if(tipo != ""){ //draw mode
            QPainter painter(this);
            QRect dirtyRect = event->rect();
            painter.drawImage(dirtyRect,image,dirtyRect);
    
        }
        else QLabel::paintEvent(event);
    }
    

    Is there a way that I can keep the image zoomed in while I draw, just like in Paint?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 4 Feb 2019, 17:52 last edited by mrjj 2 May 2019, 10:37
      #2

      Hi
      How do you zoom it, in the first place ?
      If its just by making label bigger, then maybe

      (still in paintEvent)

       if(tipo != ""){ //draw mode
              QPainter painter(this);
              QRect fullRect = rect(); // use rect of label
              painter.drawImage(dirtyRect,image,fullRect );
          }
      
      N 2 Replies Last reply 5 Feb 2019, 10:30
      0
      • M mrjj
        4 Feb 2019, 17:52

        Hi
        How do you zoom it, in the first place ?
        If its just by making label bigger, then maybe

        (still in paintEvent)

         if(tipo != ""){ //draw mode
                QPainter painter(this);
                QRect fullRect = rect(); // use rect of label
                painter.drawImage(dirtyRect,image,fullRect );
            }
        
        N Offline
        N Offline
        Nalu323
        wrote on 5 Feb 2019, 10:30 last edited by Nalu323 2 May 2019, 10:58
        #3

        @mrjj Hi, yes I zoom in/out by making the label bigger, just like in Image Viewer example, and because if I zoom in/out the image directly, it loses quality.

        1 Reply Last reply
        0
        • M mrjj
          4 Feb 2019, 17:52

          Hi
          How do you zoom it, in the first place ?
          If its just by making label bigger, then maybe

          (still in paintEvent)

           if(tipo != ""){ //draw mode
                  QPainter painter(this);
                  QRect fullRect = rect(); // use rect of label
                  painter.drawImage(dirtyRect,image,fullRect );
              }
          
          N Offline
          N Offline
          Nalu323
          wrote on 5 Feb 2019, 10:40 last edited by
          #4

          @mrjj I tried your code, here's the result:
          0_1549363016752_5cd8c55d-9905-4b92-bb0b-126715f37cae-image.png

          1 Reply Last reply
          0

          1/4

          4 Feb 2019, 16:44

          • Login

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