Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.
Scaling QPixmap image
This code snippets shows how to scale a QPixmap image.
- Install latest Nokia Qt SDK
The application supports screen orientation changes. In resizeEvent(), store the new size of the widget. This way the image can always be scaled to the correct size.
Load the image from the file system:
pixmap = 0;
// imagePath can be something like "c:/data/Images/myImage.jpg"
pixmap = new QPixmap(imagePath);
Scale the new image and draw it on the screen.
void QMyWidget::paintEvent(QPaintEvent *)
// Scale new image which size is widgetSize
QPixmap scaledPixmap = pixmap->scaled(widgetSize, Qt::KeepAspectRatio);
// Calculate image center position into screen
// Draw image
The QPixmap image has been scaled.