Paint Event and Zoomed In Image Problem



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


  • Lifetime Qt Champion

    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 );
        }
    


  • @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.



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