1

我想创建标准的原生选项菜单,在诺基亚 E52 上按选项软键后显示。它类似于这个:

菜单

我的代码如下所示:

this->changefile = menuBar()->addAction(tr("Change file"),this,SLOT(openFileChooser()));
this->changefile->setEnabled(true);

问题是当我按下应该显示此菜单的按钮时,什么也没有发生。没有菜单。我的代码有什么问题?请帮忙。

4

1 回答 1

2

以下是我创建软键菜单的方法:

//Create the action and set its softkey role
leftKeyAction_mp = new QAction( this );
leftKeyAction_mp->setText( "Options" );
leftKeyAction_mp->setSoftKeyRole( QAction::PositiveSoftKey );

//Add the action to the widget (QWidget::addAction)
addAction( leftKeyAction_mp );

//Create the menu and add set it for the action
optionsMenu_mp = new QMenu( this );
leftKeyAction_mp->setMenu( optionsMenu_mp );

//Add an action to the menu
optionsMenu_mp->addAction( "Item", this, SLOT( itemClicked() ) );

请记住,具有菜单的小部件必须是活动的顶级小部件才能显示菜单。

此致

于 2011-06-25T12:47:29.677 回答