×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Controlling Actions item in Qt context-sensitive menus

From Nokia Developer Wiki
Jump to: navigation, search
vkmunjpara (Talk | contribs)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{ReviewerApproved}}
+
{{Archived|timestamp=20120214033020|user=[[User:Hamishwillee|&lt;br /&gt;----]]|[[:Category:Qt Quick|Qt Quick]] should be used for all UI development on mobile devices. The approach described in this article (based on {{Qapiname|QWidget}}) is deprecated.}}
{{CodeSnippet
+
[[Category:Qt C++ UI]][[Category:Symbian]][[Category:How To]][[Category:Code Snippet]][[Category:UI]]
|id=n/a
+
 
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
+
{{ArticleMetaData <!-- v1.2 -->
 +
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|devices= All (S60)
 
|devices= All (S60)
|category=Qt for Symbian, 4.5.2-tower release
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|subcategory= UI
+
|platform= S60 3rd Edition, FP1, FP2<br>S60 5th Edition
|creationdate=Sept 14, 2009
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|keywords=QWidget::setContextMenuPolicy(), QWidget::setSoftKeys()
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= QWidget::setContextMenuPolicy(), QWidget::setSoftKeys()
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20090914
 +
|author= [[User:Treinio]]
 
}}
 
}}
  
 
==Description==
 
==Description==
  
Qt for Symbian allows using a context-sensitive menu to be shown in the control pane area that changes dynamically based on the focused widget. This is done by assigning softkeys (see [http://pepper.troll.no/s60prereleases/doc/qwidget.html#setSoftKeys QWidget::setSoftKeys()] for a widget. By default, a menu item for ''Actions'' (see [http://pepper.troll.no/s60prereleases/doc/qwidget.html#actions QWidget::actions()]) is added in a focused widget's options menu.<br>
+
Qt allows using a context-sensitive menu to be shown in the control pane area that changes dynamically based on the focused widget. This is done by assigning softkeys (see [http://doc.qt.nokia.com/latest/qwidget.html#setSoftKeys QWidget::setSoftKeys()] for a widget. By default, a menu item for ''Actions'' (see [http://doc.qt.nokia.com/latest/qwidget.html#actions QWidget::actions()]) is added in a focused widget's options menu.<br>
  
This behavior can be changed by controlling [http://pepper.troll.no/s60prereleases/doc/qwidget.html#contextMenuPolicy-prop context menu policy] of a widget,
+
This behavior can be changed by controlling [http://doc.qt.nokia.com/latest/qwidget.html#contextMenuPolicy-prop context menu policy] of a widget,
 
a property that holds how the widget shows a context menu.
 
a property that holds how the widget shows a context menu.
 
==Preconditions==
 
 
* [http://pepper.troll.no/s60prereleases/ Download the latest Qt for S60 distribution from Qt].
 
* Install Qt for S60:[[Installing Qt on S60]]
 
  
  
 
==Source code==
 
==Source code==
<code cpp>
+
<code cpp-qt>
 
MainWindow::MainWindow(QWidget *parent)
 
MainWindow::MainWindow(QWidget *parent)
 
     : QMainWindow(parent)
 
     : QMainWindow(parent)
Line 57: Line 67:
  
 
Text editor has a menu without any visible ''Actions'' items.  
 
Text editor has a menu without any visible ''Actions'' items.  
<br><br>
 
  
==See also==
 
  
[[CS001351 - Adding Options menu, panes, and icon to a Qt for Symbian application]]
+
==See also==
  
[[Category:Qt]][[Category:Qt for Symbian]][[Category:How To]][[Category:Code Examples]]
+
[[CS001351 - Adding Options menu, panes, and icon to a Qt application]]

Latest revision as of 04:14, 11 October 2012

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.

Article Metadata
Tested with
Devices(s): All (S60)
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Article
Keywords: QWidget::setContextMenuPolicy(), QWidget::setSoftKeys()
Created: treinio (14 Sep 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

[edit] Description

Qt allows using a context-sensitive menu to be shown in the control pane area that changes dynamically based on the focused widget. This is done by assigning softkeys (see QWidget::setSoftKeys() for a widget. By default, a menu item for Actions (see QWidget::actions()) is added in a focused widget's options menu.

This behavior can be changed by controlling context menu policy of a widget, a property that holds how the widget shows a context menu.


[edit] Source code

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
textEditor = new QTextEdit(tr("Hello"), this);
 
// Set context menu policy to 'none' to prevent Actions menu from being shown
textEditor->setContextMenuPolicy(Qt::NoContextMenu);
 
// Set softkeys to text editor for a context-sensitive menu
QAction* options = new QAction(tr("Options"), this);
options->setSoftKeyRole(QAction::MenuSoftKey);
QAction* exit = new QAction(tr("Exit"), this);
exit->setSoftKeyRole(QAction::ExitSoftKey);
 
QList<QAction*> textEditorSoftKeys;
textEditorSoftKeys.append(options);
textEditorSoftKeys.append(exit);
textEditor->setSoftKeys(textEditorSoftKeys);
 
setCentralWidget(textEditor);
 
// Add any common menu items into menu bar
fileMenu = menuBar()->addMenu(tr("&File"));
exit = new QAction(tr("&Exit"), this);
fileMenu->addAction(exit);
connect(exit, SIGNAL(triggered()), this, SLOT(close()));
}

[edit] Postconditions

Text editor has a menu without any visible Actions items.


[edit] See also

CS001351 - Adding Options menu, panes, and icon to a Qt application

This page was last modified on 11 October 2012, at 04:14.
50 page views in the last 30 days.