How to Add Options Menu in Symbian Application: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Remove non-functioning "toc" command)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:HowTo]]<br />[[Category:snippets]]
{{Outdated|reason=The Symbian platform is no longer supported.}}
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
 
[[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=&quot;yes&amp;quot; depth=&quot;2&amp;quot;]


= 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 &quot;QMainWindow&amp;quot;:http://doc.qt.nokia.com/latest/qmainwindow.html, &quot;QDialog&amp;quot;:http://doc.qt.nokia.com/latest/qdialog.html or to &quot;QWidget&amp;quot;: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.
'''Options''' menu and '''Exit''' button can be attached to [http://doc.qt.nokia.com/latest/qmainwindow.html QMainWindow], [http://doc.qt.nokia.com/latest/qdialog.html QDialog] or to [http://doc.qt.nokia.com/latest/qwidget.html QWidget] on Symbian. QMainWindow has predefined Symbian CBA buttons but they have to be defined for QDialog and QWidget.


== Preconditions ==
== Preconditions ==
Line 13: Line 16:
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><br />int main(int argc, char *argv[])<br />{<br /> QApplication app(argc, argv);
<code>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);


MainWindow mainWindow;<br /> mainWindow.showMaximized();
MainWindow mainWindow;
mainWindow.showMaximized();


return app.exec&amp;amp;#40;&amp;#41;;<br />}<br /></code>
return app.exec();
}
</code>


== Defining menus in QMainWindow ==
== Defining menus in QMainWindow ==
Line 23: Line 32:
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()<s>&gt;addAction(&quot;Example&amp;quot;, this, SLOT (exampleSlot())); <code>
<code> menuBar()->addAction("Example", this, SLOT (exampleSlot())); <code>
<br />Please note that '''exampleSlot()''' slot is called when an item is selected from the Options menu and its behavior should be also implemented.
 
<br />h2. Defining menus in QDialog or QWidget
Please note that '''exampleSlot()''' slot is called when an item is selected from the Options menu and its behavior should be also implemented.
<br />Symbian CBA buttons are not predefined for QDialog or QWidget and they have to be defined.
 
<br />An instance of &quot;QMenu&amp;quot;:http://doc.qt.nokia.com/latest/qmenu.html should be added at the header:
== Defining menus in QDialog or QWidget ==
<br /></code> QMenu* m_pMenu; </code>
Symbian CBA buttons are not predefined for QDialog or QWidget and they have to be defined.
<br />At appropriate location should be added the implementation of '''Options''' menu and the '''Exit''' button:
 
<br /><code><br />// Create menu<br />m_pMenu = new QMenu(this);<br />m_pMenu</s>&gt;addAction(&quot;Example&amp;quot;, this, SLOT (exampleSlot()));
An instance of [http://doc.qt.nokia.com/latest/qmenu.html QMenu] 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<br />QAction *pOptions = new QAction(&quot;Options&amp;quot;, this);<br />// Set defined menu into Options button<br />pOptions-&gt;setMenu(m_pMenu);<br />pOptions-&gt;setSoftKeyRole(QAction::PositiveSoftKey);<br />addAction(pOptions);
// 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<br />QAction *pExitButton = new QAction(QString(&quot;Exit&amp;quot;), this);<br />pExitButton-&gt;setSoftKeyRole(QAction::NegativeSoftKey);<br />// Exit button closes the application<br />QObject::connect(pExitButton, SIGNAL (triggered()),<br />QApplication::instance(), SLOT (quit()));<br />addAction(pExitButton);<br /></code>
// 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 70:
= See also =
= See also =


&quot;Remove actions option menu in Symbian<br />&quot;:http://developer.qt.nokia.com/wiki/Remove_actions_options_menu_in_Symbian
[http://developer.qt.nokia.com/wiki/Remove_actions_options_menu_in_Symbian Remove actions option menu in Symbian
]


= References =
= References =

Latest revision as of 12:21, 17 April 2015

IMPORTANT: The content of this page is outdated. Reason: The Symbian platform is no longer supported.
If you have checked or updated this page and found the content to be suitable, please remove this notice.
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

English Български


How to Add Options Menu in Symbian Application

Options menu and Exit button can be attached to QMainWindow, QDialog or to QWidget 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();
}

Defining menus in QMainWindow

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.

== 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 [http://doc.qt.nokia.com/latest/qmenu.html QMenu] 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

[http://developer.qt.nokia.com/wiki/Remove_actions_options_menu_in_Symbian Remove actions option menu in Symbian ]

References