×
Namespaces

Variants
Actions
Revision as of 08:20, 20 September 2009 by nayan_trivedi (Talk | contribs)

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

From Nokia Developer Wiki
Jump to: navigation, search
{{{width}}}
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Article
Keywords: QWidget::setPalette(), QPalette::setBrush, QPixmap(),QPixmap::scaled()
Created: (11 Jun 2009)
Last edited: nayan_trivedi (20 Sep 2009)

Contents

Overview

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.

Preconditions

Headers required

#include <QPalette>
#include <QDesktopWidget>

Source

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 reqirement..
QPixmap pixmap(pixmap1.scaled(size));
 
p.setBrush(QPalette::Background, pixmap);
setPalette(p);
}


Postconditions

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

BackImage.JPG

Code Example

  • The Code Example will set image in background and example is tested on Nokia 5800 XpressMusic.
298 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×