Namespaces

Variants
Actions

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 over the next few weeks. Thanks for all your past and future contributions.

Archived:如何在Symbian应用程序/widget中使用Qt加载和缩放图片

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

代码示例
兼容于
平台:
Symbian

文章
翻译:
hoolee
最后由 hamishwillee 在 11 Oct 2012 编辑

Contents

简介

下列代码片段演示了如何加载图片,缩放图片以及如何将图片设置为程序或widget的背景图。这里的API QPixmap()将可以传入文件名然后加载图片,API QPixmap::scaled()'将返回给定高宽缩放后的图片拷贝,QPalette::setBrush() Brush颜色,QWidget::setPalette() 为widget设置给定的调色板。

下列代码自签名即可执行,并无用到需要额外能力的API

需要的头文件

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


后记

上述代码在一个程序中显示了背景图

BackImage.JPG

示例代码

  • Code Example将背景图设置为上述图片,已经在Nokia 5800 XpressMusic手机测试
This page was last modified on 11 October 2012, at 01:15.
377 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.

×