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:在Qt Symbian中如何修改手机的软键(softkey)

From Wiki
Jump to: navigation, search

Archived.png存档: 这篇文章是存档,因为考虑到今天它与第三方开发者建立商业解决方案不相关。

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

文章
关键词: QWidget::setSoftKeys, setSoftKeyRole
翻译:
bugatcuteqt
最后由 hamishwillee 在 11 Oct 2012 编辑


在做手机应用的时候经常会要碰到修改手机屏幕上软键显示的问题,比如想把”退出”改为”返回”,”取消”等,同时也改变选中该软键时的行为,不是标准的退出应用。

Nokia论坛上有一篇文章Change_SoftKey_labels_of_widget_in_Qt 介绍了在Symbian Qt中如何处理这个问题,不过该文介绍的方法只适合Qt-4.6以前的版本,因为Qt-4.6以后的版本没有了文章所说的 QWidget::setSoftKeys(), 改由另外的机制来实现。

Qt-4.6以后的版本使用QAction::setSoftKeyRole(SoftKeyRole softKeyRole),SoftKeyRole可用的值有QAction::NoSoftKey,QAction::PositiveSoftKey,QAction::NegativeSoftKey,QAction::SelectSoftKey 分别代表没有映射,左键,右键和中键。软件上的文字则有QAction中的文本来确定。软键的内容变化由当前获得焦点的Widget的QAction来确定,当然需要该QAction要执行setSoftKeyRole才能关联到软键上

下面是一段不长的代码,演示了如何修改手机软键

#include <QtGui>
 
class Widget:public QWidget{
public:
Widget(QWidget *parent);
};
 
int main(int argc,char *argv[]){
QApplication app(argc,argv);
QMainWindow mw;
Widget *w=new Widget(&mw);
mw.setCentralWidget(w);
mw.showMaximized();
return app.exec();
}
 
Widget::Widget(QWidget *parent):QWidget(parent){
QVBoxLayout *layout=new QVBoxLayout(this);
 
QPushButton *helloqt=new QPushButton("Hello Qt",this);
QAction *actI=new QAction(QObject::tr("Qt"),this);
actI->setSoftKeyRole(QAction::PositiveSoftKey);
helloqt->addAction(actI);
 
QPushButton *hellomaemo=new QPushButton("Hello Maemo",this);
QAction *actII=new QAction(QObject::tr("Maemo"),this);
actII->setSoftKeyRole(QAction::SelectSoftKey);
hellomaemo->addAction(actII);
 
QPushButton *hellos60=new QPushButton("Hello S60",this);
QAction *actIII=new QAction(QObject::tr("S60"),this);
actIII->setSoftKeyRole(QAction::NegativeSoftKey);
hellos60->addAction(actIII);
 
layout->addWidget(helloqt);
layout->addWidget(hellomaemo);
layout->addWidget(hellos60);
layout->addStretch();
 
}

根据当前选了不同按钮,可以看到软键上显示的信息在变化,大家去试的时候可能会发现SelectSoftKey没起作用,应该是系统没有使能 MSKEnabled()的原因。
Softkey customize.png

This page was last modified on 11 October 2012, at 01:15.
348 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.

×