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

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
'''English''' [[How to Add Options Menu in Symbian Application Bulgarian|Български]]
[[Category:HowTo]]<br />[[Category:snippets]]


=How to Add Options Menu in Symbian Application=
'''English''' [[How_to_Add_Options_Menu_in_Symbian_Application_Bulgarian|Български]]


'''Options''' menu and '''Exit''' button can be attached to [http://doc.qt.nokia.com/latest/qmainwindow.html QMainWindow] ''[doc.qt.nokia.com]'', [http://doc.qt.nokia.com/latest/qdialog.html QDialog] ''[doc.qt.nokia.com]'' or to [http://doc.qt.nokia.com/latest/qwidget.html QWidget] ''[doc.qt.nokia.com]'' on Symbian. QMainWindow has predefined Symbian <span class="caps">CBA</span> buttons but they have to be defined for QDialog and QWidget.
[toc align_right=&quot;yes&amp;quot; depth=&quot;2&amp;quot;]


==Preconditions==
= How to Add Options Menu in Symbian Application =


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:
'''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.


==Defining menus in QMainWindow==
== Preconditions ==


QMainWindow has predefined Symbian <span class="caps">CBA</span> buttons so different options can be added to the '''Options''' menu by adding a new action.
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:


Please note that '''exampleSlot()''' slot is called when an item is selected from the Options menu and its behavior should be also implemented.
<code><br />int main(int argc, char *argv[])<br />{<br /> QApplication app(argc, argv);


==Defining menus in QDialog or QWidget==
MainWindow mainWindow;<br /> mainWindow.showMaximized();


Symbian <span class="caps">CBA</span> buttons are not predefined for QDialog or QWidget and they have to be defined.
return app.exec&amp;amp;#40;&amp;#41;;<br />}<br /></code>


An instance of [http://doc.qt.nokia.com/latest/qmenu.html QMenu] ''[doc.qt.nokia.com]'' should be added at the header:
== Defining menus in QMainWindow ==


At appropriate location should be added the implementation of '''Options''' menu and the '''Exit''' button:
QMainWindow has predefined Symbian CBA buttons so different options can be added to the '''Options''' menu by adding a new action.


Of course the right button can be used '''not''' only to close the application as it can be connected to other slot.
<code> menuBar()<s>&gt;addAction(&quot;Example&amp;quot;, 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
<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:
<br /></code> QMenu* m_pMenu; </code>
<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()));


=See also=
// 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);


[http://developer.qt.nokia.com/wiki/Remove_actions_options_menu_in_Symbian Remove actions option menu in Symbian] ''[developer.qt.nokia.com]''
// 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>


=References=
Of course the right button can be used '''not''' only to close the application as it can be connected to other slot.


[http://wiki.forum.nokia.com/index.php/CS001351_-_Adding_Options_menu,_panes,_and_icon_to_a_Qt_for_Symbian_application Forum Nokia: Adding Options menu, panes and icon to a Qt for Symbian application] ''[wiki.forum.nokia.com]''
= See also =


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


* [[:Category:HowTo|HowTo]]
= References =
* [[:Category:snippets|snippets]]

Revision as of 10:51, 24 February 2015


English Български

[toc align_right="yes&quot; depth="2&quot;]

How to Add Options Menu in Symbian Application

Options menu and Exit button can be attached to "QMainWindow&quot;:http://doc.qt.nokia.com/latest/qmainwindow.html, "QDialog&quot;:http://doc.qt.nokia.com/latest/qdialog.html or to "QWidget&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.

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:

<br />int main(int argc, char *argv[])<br />{<br /> QApplication app(argc, argv);

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

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

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()<s>&gt;addAction(&quot;Example&amp;quot;, 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
<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:
<br />

QMenu* m_pMenu;


At appropriate location should be added the implementation of Options menu and the Exit button:


<br />// Create menu<br />m_pMenu = new QMenu(this);<br />m_pMenu</s>&gt;addAction(&quot;Example&amp;quot;, 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 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 />

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

References