Draw on the center of widget
Solved
General and Desktop
-
I'm trying to draw an image on the center of a widget using the
paintEvent
and I'm doing like this:QPainter painter; painter.drawPixmap(QPoint(width() / 2 - mLogotype->width() / 2, height() / 2 - mLogotype->height() / 2), mLogotype);
Is there a more convenient way for doing that?
The
mLogotype
is aQPixmap
. -
You already have it in one line so there's little to be improved, but you can also do:
painter.drawPixmap((rect().bottomRight() - mLogotype.rect().bottomRight()) / 2, mLogotype);
Btw. In your example there's
QPointer
. I think you meantQPoint
. -
@Chris-Kawa Yes, it's point and thank you for the improvement. :D