Qt6 topics merged with General

Need help optimizing the design of an image editor program

  • I am creating an image editor where I perform pixel manipulations to a QImage object, and use a QPixmap (displayed through a QLabel) to represent the changes made to the QImage. The reason why I am using two separate objects for the image is that the QLabel is resizable (to offer the user a better view), and hence, the QPixmap may not be the exact representation of the image. For a better explanation of the relationship between the objects, see the following diagram:

    please enable images

    Therefore, this is what is happening in my program:

    • The user performs mouse movements over the QLabel, in order to edit the image.
    • The x, y coordinates of the mouse events are used to determine the particular pixel of the QPixmap (the resized image).
    • The pixel's x, y values and the resize factor of the QPixmap are used to determine the target pixel of the QImage.
    • The target pixel is modified.
    • A new QPixmap is created from the modified QImage, which is then used to replace the old one.

    As you can probably guess, this design is pretty slow. It won't be a big issue for smaller images, but for larger images I need to speed things up. How do I do it? How do programs like Photoshop achieve this?

  • Hi,
    QPainter can draw a QImage. So you can for example create a new Widget, subclass for QLabel for example if you want and reimplement paintEvent. Like this you work all the time with your QImage without creating another one.
    And better you can only update the region that changed, no need to refresh everything. I did not try it but it should work.