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.

Archived:Load, Resize image and set background image in Qt application/widget

From Wiki
Jump to: navigation, search

Archived.pngArchived: 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 (based on QWidget) is deprecated.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Platform(s): Qt
Keywords: QWidget::setPalette(), QPalette::setBrush, QPixmap(),QPixmap::scaled()
Created: savaj (11 Jun 2009)
Last edited: hamishwillee (11 Oct 2012)



This code snippets shows how to load image, resize image and set image in background of widget/application. The API QPixmap() will load image using file name. API QPixmap::scaled() will returns a copy of the pixmap scaled to a rectangle with the given width and height. QPalette::setBrush() sets the brush for the given color role (here background) to the specified brush (here image)for all groups in the palette. QWidget::setPalette() set a given palette for a Widget.

This snippet can be self-signed. As it does not use any API which require developer/certified signing.

Headers required

#include <QPalette>
#include <QDesktopWidget>


void SetBackground::SetBackgroundImage()
//Using QPalette you can set background image as follows.
QPalette p = palette();
//Load image to QPixmap, Give full path of image
QPixmap pixmap1("c://01.JPG"); //For emulator C: is ..\epoc32\winscw\c so image must be at that location
//resize image if it is larger than screen size.
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect rect = desktopWidget->availableGeometry();
QSize size(rect.width() , rect.height());
//resize as per your requirement..
QPixmap pixmap(pixmap1.scaled(size));
p.setBrush(QPalette::Background, pixmap);


The code snippet is expected to show background image in application.


Code Example

  • The Code Example will set image in background and example is tested on Nokia 5800 XpressMusic.
This page was last modified on 11 October 2012, at 01:14.
251 page views in the last 30 days.