Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:Controlling Actions item in Qt context-sensitive menus

From Wiki
Jump to: navigation, search

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)
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Keywords: QWidget::setContextMenuPolicy(), QWidget::setSoftKeys()
Created: treinio (14 Sep 2009)
Last edited: hamishwillee (11 Oct 2012)



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.

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
// Set softkeys to text editor for a context-sensitive menu
QAction* options = new QAction(tr("Options"), this);
QAction* exit = new QAction(tr("Exit"), this);
QList<QAction*> textEditorSoftKeys;
// Add any common menu items into menu bar
fileMenu = menuBar()->addMenu(tr("&File"));
exit = new QAction(tr("&Exit"), this);
connect(exit, SIGNAL(triggered()), this, SLOT(close()));


Text editor has a menu without any visible Actions items.

See also

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

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

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.