Archived:Controlling Actions item in Qt context-sensitive menus
hamishwillee
(Talk | contribs) m (Added category Category:Symbian. (Preparing for ontology change)) |
hamishwillee
(Talk | contribs) m (Minor tweeks) |
||
| Line 1: | Line 1: | ||
| + | [[Category:Qt]][[Category:Symbian]] | ||
{{ReviewerApproved}} | {{ReviewerApproved}} | ||
{{CodeSnippet | {{CodeSnippet | ||
| Line 4: | Line 5: | ||
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition | |platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition | ||
|devices= All (S60) | |devices= All (S60) | ||
| − | |category=Qt | + | |category=Qt, Symbian |
|subcategory= UI | |subcategory= UI | ||
|creationdate=Sept 14, 2009 | |creationdate=Sept 14, 2009 | ||
| Line 12: | Line 13: | ||
==Description== | ==Description== | ||
| − | Qt | + | 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:// | + | 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. | ||
| − | |||
| − | |||
| − | |||
| − | |||
| Line 62: | Line 59: | ||
[[CS001351 - Adding Options menu, panes, and icon to a Qt for Symbian application]] | [[CS001351 - Adding Options menu, panes, and icon to a Qt for Symbian application]] | ||
| − | + | [[Category:How To]][[Category:Code Examples]] | |
Revision as of 10:43, 4 April 2011
Article Metadata
Tested with
Devices(s): All (S60)
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
S60 5th Edition
Article
Keywords: QWidget::setContextMenuPolicy(), QWidget::setSoftKeys()
Created: (14 Sep 2009)
Last edited: hamishwillee
(04 Apr 2011)
Contents |
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.
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()));
}
Postconditions
Text editor has a menu without any visible Actions items.
See also
CS001351 - Adding Options menu, panes, and icon to a Qt for Symbian application

