Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
How to Add Options Menu in Symbian Application: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
[[Category:HowTo]] | [[Category:HowTo]] | ||
[[Category:snippets]] | |||
'''English''' [[How_to_Add_Options_Menu_in_Symbian_Application_Bulgarian|Български]] | '''English''' [[How_to_Add_Options_Menu_in_Symbian_Application_Bulgarian|Български]] | ||
[toc align_right= | [toc align_right="yes" depth="2"] | ||
= How to Add Options Menu in Symbian Application = | = How to Add Options Menu in Symbian Application = | ||
'''Options''' menu and '''Exit''' button can be attached to | '''Options''' menu and '''Exit''' button can be attached to "QMainWindow":http://doc.qt.nokia.com/latest/qmainwindow.html, "QDialog":http://doc.qt.nokia.com/latest/qdialog.html or to "QWidget":http://doc.qt.nokia.com/latest/qwidget.html on Symbian. QMainWindow has predefined Symbian CBA buttons but they have to be defined for QDialog and QWidget. | ||
== Preconditions == | == Preconditions == | ||
Line 13: | Line 14: | ||
Make sure that the status pane and the control pane of the application are enabled. To do it call method '''showMaximized()''' of the main window: | Make sure that the status pane and the control pane of the application are enabled. To do it call method '''showMaximized()''' of the main window: | ||
<code> | <code> | ||
int main(int argc, char *argv[]) | |||
{ | |||
QApplication app(argc, argv); | |||
MainWindow mainWindow; | MainWindow mainWindow; | ||
mainWindow.showMaximized(); | |||
return app.exec | return app.exec(); | ||
} | |||
</code> | |||
== Defining menus in QMainWindow == | == Defining menus in QMainWindow == | ||
Line 23: | Line 30: | ||
QMainWindow has predefined Symbian CBA buttons so different options can be added to the '''Options''' menu by adding a new action. | QMainWindow has predefined Symbian CBA buttons so different options can be added to the '''Options''' menu by adding a new action. | ||
<code> menuBar() | <code> menuBar()->addAction("Example", this, SLOT (exampleSlot())); <code> | ||
Please note that '''exampleSlot()''' slot is called when an item is selected from the Options menu and its behavior should be also implemented. | |||
// Create | h2. Defining menus in QDialog or QWidget | ||
Symbian CBA buttons are not predefined for QDialog or QWidget and they have to be defined. | |||
An instance of "QMenu":http://doc.qt.nokia.com/latest/qmenu.html should be added at the header: | |||
</code> QMenu* m_pMenu; </code> | |||
At appropriate location should be added the implementation of '''Options''' menu and the '''Exit''' button: | |||
<code> | |||
// Create menu | |||
m_pMenu = new QMenu(this); | |||
m_pMenu->addAction("Example", this, SLOT (exampleSlot())); | |||
// Create Options CBA | |||
QAction *pOptions = new QAction("Options", this); | |||
// Set defined menu into Options button | |||
pOptions->setMenu(m_pMenu); | |||
pOptions->setSoftKeyRole(QAction::PositiveSoftKey); | |||
addAction(pOptions); | |||
// Create Exit CBA | |||
QAction *pExitButton = new QAction(QString("Exit"), this); | |||
pExitButton->setSoftKeyRole(QAction::NegativeSoftKey); | |||
// Exit button closes the application | |||
QObject::connect(pExitButton, SIGNAL (triggered()), | |||
QApplication::instance(), SLOT (quit())); | |||
addAction(pExitButton); | |||
</code> | |||
Of course the right button can be used '''not''' only to close the application as it can be connected to other slot. | Of course the right button can be used '''not''' only to close the application as it can be connected to other slot. | ||
Line 40: | Line 69: | ||
= See also = | = See also = | ||
"Remove actions option menu in Symbian | |||
":http://developer.qt.nokia.com/wiki/Remove_actions_options_menu_in_Symbian | |||
= References = | = References = |
Revision as of 11:11, 25 February 2015
English Български
[toc align_right="yes" depth="2"]
How to Add Options Menu in Symbian Application
Options menu and Exit button can be attached to "QMainWindow":http://doc.qt.nokia.com/latest/qmainwindow.html, "QDialog":http://doc.qt.nokia.com/latest/qdialog.html or to "QWidget":http://doc.qt.nokia.com/latest/qwidget.html on Symbian. QMainWindow has predefined Symbian CBA buttons but they have to be defined for QDialog and QWidget.
Preconditions
Make sure that the status pane and the control pane of the application are enabled. To do it call method showMaximized() of the main window:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.showMaximized();
return app.exec();
}
QMainWindow has predefined Symbian CBA buttons so different options can be added to the Options menu by adding a new action.
menuBar()->addAction("Example", this, SLOT (exampleSlot())); <code>
Please note that '''exampleSlot()''' slot is called when an item is selected from the Options menu and its behavior should be also implemented.
h2. Defining menus in QDialog or QWidget
Symbian CBA buttons are not predefined for QDialog or QWidget and they have to be defined.
An instance of "QMenu":http://doc.qt.nokia.com/latest/qmenu.html should be added at the header:
QMenu* m_pMenu;
At appropriate location should be added the implementation of Options menu and the Exit button:
// Create menu
m_pMenu = new QMenu(this);
m_pMenu->addAction("Example", this, SLOT (exampleSlot()));
// Create Options CBA
QAction *pOptions = new QAction("Options", this);
// Set defined menu into Options button
pOptions->setMenu(m_pMenu);
pOptions->setSoftKeyRole(QAction::PositiveSoftKey);
addAction(pOptions);
// Create Exit CBA
QAction *pExitButton = new QAction(QString("Exit"), this);
pExitButton->setSoftKeyRole(QAction::NegativeSoftKey);
// Exit button closes the application
QObject::connect(pExitButton, SIGNAL (triggered()),
QApplication::instance(), SLOT (quit()));
addAction(pExitButton);
Of course the right button can be used not only to close the application as it can be connected to other slot.
See also
"Remove actions option menu in Symbian ":http://developer.qt.nokia.com/wiki/Remove_actions_options_menu_in_Symbian