2011-06-25 49 views
1

我想創建標準原生選項菜單,在諾基亞E52上按Options軟鍵後顯示。 它類似於這樣一個東西:使用Qt在S60設備上創建選項菜單的問題

menu

我的代碼看起來像:

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

問題是,當我按下按鈕應該顯示這個菜單中沒有任何反應。沒有菜單。我的代碼有什麼問題?請幫忙。

+1

你是否在模擬器上運行你的應用程序?我使用Qt Creator 2.0.1,如果我在模擬器上運行我的應用程序,選項菜單不會彈出。然而,在一個設備上,它工作得很好。 – Yuliya

回答

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())); 

請記住,它有菜單的構件必須是一個積極的頂層窗口小部件的菜單顯示。

此致敬禮