Archived:如何在Symbian应用程序/widget中使用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 (based on QWidget) is deprecated.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.
文章信息
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);
}
后记
上述代码在一个程序中显示了背景图
示例代码
- Code Example将背景图设置为上述图片,已经在Nokia 5800 XpressMusic手机测试


(no comments yet)