Aquarius_Girl
Aquarius_Girl

Reputation: 22906

What do you mean by drawing an image in Qt/QML?

https://doc.qt.io/archives/qt-5.11/qpainter.html#drawImage-5

void QPainter::drawImage(const QRect &rectangle, const QImage &image)

Draws the given image into the given rectangle.

They have used the word draw for a reason. I believe if I have an image I can myself put it in a rectangle. I don't need a specialized function for that.

What does this function do besides putting the image in the rectangle?

Is it somehow more efficient than the following?

Rectangle
{
   height: 100; width: 100
   Image
   {
      source: "xyz.png"
   }
}

Upvotes: 2

Views: 349

Answers (1)

eyllanesc
eyllanesc

Reputation: 243897

Short answer: You are confusing concepts: QImage is not the same as QML Image item, and similar for QRect and Rectangle.

Long answer:

QImage is a class that allows to represent an image, in simple words it is a container of the bytes that represent the image and how those bytes are related. Instead Image is an Item that allows displaying an image.

QPainter's drawImage method paints a rectangle over a QImage (changes a few bytes to represent the rectangle). Instead in your code you are creating an Item Rectangle where you place an Item Image.

Facts:

  • QImage and QRect are not visual elements

  • QImage can be taken as a base for painting a visual element.

  • QPainter is used for low level painting unlike QML items (Items are painted using QPainter)

Upvotes: 3

Related Questions