Archived:Rotate picture in Qt
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic, Nokia N900
Compatibility
Platform(s): Qt
Article
Keywords: QPixmap, QPainter
Created: tepaa
(20 Oct 2009)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Overview
This example shows how to rotate a QPixmap picture using the QPainter class.
Preconditions
- Qt is installed on your platform.
- Download Qt release from here: [1]
- Qt on Maemo can be found here: Qt4 Maemo port
Header
private:
// Original pixmap that will be rotated
QPixmap pixmap;
Source
// Create new rotatedPixmap that size is same as original
QPixmap rotatedPixmap(pixmap.size());
// Create a QPainter for it
QPainter p(&rotatedPixmap);
// Set rotation origo into pixmap center
QSize size = pixmap.size();
p.translate(size.height()/2,size.height()/2);
// Rotate the painter 90 degrees
p.rotate(90);
// Set origo back to upper left corner
p.translate(-size.height()/2,-size.height()/2);
// Draw your original pixmap on it
p.drawPixmap(0, 0, pixmap);
p.end();
// Change original pixmap reference into new rotated pixmap
pixmap = rotatedPixmap;
Postconditions
The picture is rotated 90 degrees.


(no comments yet)