c++qtqimageqpixmap

What is the difference between QImage and QPixmap?


I do not understand what is the difference between QImage and QPixmap, they seem to offer the same functionality. When should I use a QImage and when should I use a QPixmap?


Solution

  • Easilly answered by reading the docs on QImage and QPixmap:

    The QPixmap class is an off-screen image representation that can be used as a paint device.

    The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.

    Edit: Also, from @Dave's answer:

    You can't manipulate a QPixmap outside the GUI-thread, but QImage has no such restriction.

    And from @Arnold:

    Here's a short summary that usually (not always) applies:

    • If you plan to manipulate an image, modify it, change pixels on it, etc., use a QImage.
    • If you plan to draw the same image more than once on the screen, convert it to a QPixmap.