<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- qshortcut.cpp --> <head> <title>Qt 4.6: QShortcut Class Reference</title> <link href="classic.css" rel="stylesheet" type="text/css" /> </head> <body> <a name="//apple_ref/cpp/cl//QShortcut"></a> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td> <td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="functions.html"><font color="#004faf">All Functions</font></a> · <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">QShortcut Class Reference<br /><span class="small-subtitle">[<a href="qtgui.html">QtGui</a> module]</span> </h1> <p>The QShortcut class is used to create keyboard shortcuts. <a href="#details">More...</a></p> <pre> #include <QShortcut></pre><p>Inherits <a href="qobject.html">QObject</a>.</p> <ul> <li><a href="qshortcut-members.html">List of all members, including inherited members</a></li> </ul> <hr /> <a name="properties"></a> <h2>Properties</h2> <p><table class="propsummary" width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td width="45%" valign="top"><ul> <li><div class="fn"><b><a href="qshortcut.html#autoRepeat-prop">autoRepeat</a></b> : bool</div></li> <li><div class="fn"><b><a href="qshortcut.html#context-prop">context</a></b> : Qt::ShortcutContext</div></li> <li><div class="fn"><b><a href="qshortcut.html#enabled-prop">enabled</a></b> : bool</div></li> </ul></td><td valign="top"><ul> <li><div class="fn"><b><a href="qshortcut.html#key-prop">key</a></b> : QKeySequence</div></li> <li><div class="fn"><b><a href="qshortcut.html#whatsThis-prop">whatsThis</a></b> : QString</div></li> </ul> </td></tr> </table></p> <ul> <li><div bar="2" class="fn"></div>1 property inherited from <a href="qobject.html#properties">QObject</a></li> </ul> <hr /> <a name="public-functions"></a> <h2>Public Functions</h2> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#QShortcut">QShortcut</a></b> ( QWidget * <i>parent</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#QShortcut-2">QShortcut</a></b> ( const QKeySequence & <i>key</i>, QWidget * <i>parent</i>, const char * <i>member</i> = 0, const char * <i>ambiguousMember</i> = 0, Qt::ShortcutContext <i>context</i> = Qt::WindowShortcut )</td></tr> <tr><td class="memItemLeft" align="right" valign="top"></td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#dtor.QShortcut">~QShortcut</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#autoRepeat-prop">autoRepeat</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">Qt::ShortcutContext </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#context-prop">context</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#id">id</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#enabled-prop">isEnabled</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QKeySequence </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#key-prop">key</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QWidget * </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#parentWidget">parentWidget</a></b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#autoRepeat-prop">setAutoRepeat</a></b> ( bool <i>on</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#context-prop">setContext</a></b> ( Qt::ShortcutContext <i>context</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#enabled-prop">setEnabled</a></b> ( bool <i>enable</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#key-prop">setKey</a></b> ( const QKeySequence & <i>key</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#whatsThis-prop">setWhatsThis</a></b> ( const QString & <i>text</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">QString </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#whatsThis-prop">whatsThis</a></b> () const</td></tr> </table> <ul> <li><div bar="2" class="fn"></div>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li> </ul> <hr /> <a name="signals"></a> <h2>Signals</h2> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#activated">activated</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qshortcut.html#activatedAmbiguously">activatedAmbiguously</a></b> ()</td></tr> </table> <ul> <li><div bar="2" class="fn"></div>1 signal inherited from <a href="qobject.html#signals">QObject</a></li> </ul> <h3>Additional Inherited Members</h3> <ul> <li><div class="fn"></div>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li> <li><div class="fn"></div>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li> <li><div class="fn"></div>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li> </ul> <a name="details"></a> <hr /> <h2>Detailed Description</h2> <p>The QShortcut class is used to create keyboard shortcuts.</p> <p>The QShortcut class provides a way of connecting keyboard shortcuts to Qt's <a href="signalsandslots.html">signals and slots</a> mechanism, so that objects can be informed when a shortcut is executed. The shortcut can be set up to contain all the key presses necessary to describe a keyboard shortcut, including the states of modifier keys such as <b>Shift</b>, <b>Ctrl</b>, and <b>Alt</b>.</p> <a name="mnemonic"></a><p>On certain widgets, using '&' in front of a character will automatically create a mnemonic (a shortcut) for that character, e.g. "E&xit" will create the shortcut <b>Alt+X</b> (use '&&' to display an actual ampersand). The widget might consume and perform an action on a given shortcut. On X11 the ampersand will not be shown and the character will be underlined. On Windows, shortcuts are normally not displayed until the user presses the <b>Alt</b> key, but this is a setting the user can change. On Mac, shortcuts are disabled by default. Call <a href="qtglobal.html#qt_set_sequence_auto_mnemonic">qt_set_sequence_auto_mnemonic</a>() to enable them. However, because mnemonic shortcuts do not fit in with Aqua's guidelines, Qt will not show the shortcut character underlined.</p> <p>For applications that use menus, it may be more convenient to use the convenience functions provided in the <a href="qmenu.html">QMenu</a> class to assign keyboard shortcuts to menu items as they are created. Alternatively, shortcuts may be associated with other types of actions in the <a href="qaction.html">QAction</a> class.</p> <p>The simplest way to create a shortcut for a particular widget is to construct the shortcut with a key sequence. For example:</p> <pre> shortcut = new QShortcut(QKeySequence(tr("Ctrl+O", "File|Open")), parent);</pre> <p>When the user types the <a href="qkeysequence.html">key sequence</a> for a given shortcut, the shortcut's <a href="qshortcut.html#activated">activated</a>() signal is emitted. (In the case of ambiguity, the <a href="qshortcut.html#activatedAmbiguously">activatedAmbiguously</a>() signal is emitted.) A shortcut is "listened for" by Qt's event loop when the shortcut's parent widget is receiving events.</p> <p>A shortcut's key sequence can be set with <a href="qshortcut.html#key-prop">setKey</a>() and retrieved with <a href="qshortcut.html#key-prop">key</a>(). A shortcut can be enabled or disabled with <a href="qshortcut.html#enabled-prop">setEnabled</a>(), and can have "What's This?" help text set with <a href="qshortcut.html#whatsThis-prop">setWhatsThis</a>().</p> <p>See also <a href="qshortcutevent.html">QShortcutEvent</a>, <a href="qkeysequence.html">QKeySequence</a>, and <a href="qaction.html">QAction</a>.</p> <hr /> <h2>Property Documentation</h2> <a name="//apple_ref/cpp/instm/QShortcut/autoRepeat"></a> <a name="//apple_ref/cpp/instm/QShortcut/setAutoRepeat"></a> <h3 class="fn"><a name="autoRepeat-prop"></a>autoRepeat : bool</h3> <p>This property holds whether the shortcut can auto repeat.</p> <p>If true, the shortcut will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.</p> <p>This property was introduced in Qt 4.2.</p> <p><b>Access functions:</b></p> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b>autoRepeat</b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b>setAutoRepeat</b> ( bool <i>on</i> )</td></tr> </table> <a name="//apple_ref/cpp/instm/QShortcut/context"></a> <a name="//apple_ref/cpp/instm/QShortcut/setContext"></a> <h3 class="fn"><a name="context-prop"></a>context : <a href="qt.html#ShortcutContext-enum">Qt::ShortcutContext</a></h3> <p>This property holds the context in which the shortcut is valid.</p> <p>A shortcut's context decides in which circumstances a shortcut is allowed to be triggered. The normal context is <a href="qt.html#ShortcutContext-enum">Qt::WindowShortcut</a>, which allows the shortcut to trigger if the parent (the widget containing the shortcut) is a subwidget of the active top-level window.</p> <p>By default, this property is set to <a href="qt.html#ShortcutContext-enum">Qt::WindowShortcut</a>.</p> <p><b>Access functions:</b></p> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">Qt::ShortcutContext </td><td class="memItemRight" valign="bottom"><b>context</b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b>setContext</b> ( Qt::ShortcutContext <i>context</i> )</td></tr> </table> <a name="//apple_ref/cpp/instm/QShortcut/isEnabled"></a> <a name="//apple_ref/cpp/instm/QShortcut/setEnabled"></a> <h3 class="fn"><a name="enabled-prop"></a>enabled : bool</h3> <p>This property holds whether the shortcut is enabled.</p> <p>An enabled shortcut emits the <a href="qshortcut.html#activated">activated</a>() or <a href="qshortcut.html#activatedAmbiguously">activatedAmbiguously</a>() signal when a <a href="qshortcutevent.html">QShortcutEvent</a> occurs that matches the shortcut's <a href="qshortcut.html#key-prop">key</a>() sequence.</p> <p>If the application is in <tt>WhatsThis</tt> mode the shortcut will not emit the signals, but will show the "What's This?" text instead.</p> <p>By default, this property is true.</p> <p><b>Access functions:</b></p> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b>isEnabled</b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b>setEnabled</b> ( bool <i>enable</i> )</td></tr> </table> <p>See also <a href="qshortcut.html#whatsThis-prop">whatsThis</a>.</p> <a name="//apple_ref/cpp/instm/QShortcut/key"></a> <a name="//apple_ref/cpp/instm/QShortcut/setKey"></a> <h3 class="fn"><a name="key-prop"></a>key : <a href="qkeysequence.html">QKeySequence</a></h3> <p>This property holds the shortcut's key sequence.</p> <p>This is a key sequence with an optional combination of Shift, Ctrl, and Alt. The key sequence may be supplied in a number of ways:</p> <pre> setKey(0); <span class="comment">// no signal emitted</span> setKey(QKeySequence()); <span class="comment">// no signal emitted</span> setKey(0x3b1); <span class="comment">// Greek letter alpha</span> setKey(Qt::Key_D); <span class="comment">// 'd', e.g. to delete</span> setKey('q'); <span class="comment">// 'q', e.g. to quit</span> setKey(Qt::CTRL + Qt::Key_P); <span class="comment">// Ctrl+P, e.g. to print document</span> setKey("Ctrl+P"); <span class="comment">// Ctrl+P, e.g. to print document</span></pre> <p>By default, this property contains an empty key sequence.</p> <p><b>Access functions:</b></p> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">QKeySequence </td><td class="memItemRight" valign="bottom"><b>key</b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b>setKey</b> ( const QKeySequence & <i>key</i> )</td></tr> </table> <a name="//apple_ref/cpp/instm/QShortcut/whatsThis"></a> <a name="//apple_ref/cpp/instm/QShortcut/setWhatsThis"></a> <h3 class="fn"><a name="whatsThis-prop"></a>whatsThis : <a href="qstring.html">QString</a></h3> <p>This property holds the shortcut's "What's This?" help text.</p> <p>The text will be shown when the application is in "What's This?" mode and the user types the shortcut <a href="qshortcut.html#key-prop">key</a>() sequence.</p> <p>To set "What's This?" help on a menu item (with or without a shortcut key), set the help on the item's action.</p> <p>By default, this property contains an empty string.</p> <p><b>Access functions:</b></p> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">QString </td><td class="memItemRight" valign="bottom"><b>whatsThis</b> () const</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b>setWhatsThis</b> ( const QString & <i>text</i> )</td></tr> </table> <p>See also <a href="qwhatsthis.html#inWhatsThisMode">QWhatsThis::inWhatsThisMode</a>() and <a href="qaction.html#whatsThis-prop">QAction::setWhatsThis</a>().</p> <hr /> <h2>Member Function Documentation</h2> <a name="//apple_ref/cpp/instm/QShortcut/QShortcut"></a> <h3 class="fn"><a name="QShortcut"></a>QShortcut::QShortcut ( <a href="qwidget.html">QWidget</a> * <i>parent</i> )</h3> <p>Constructs a <a href="qshortcut.html">QShortcut</a> object for the <i>parent</i> widget. Since no shortcut key sequence is specified, the shortcut will not emit any signals.</p> <p>See also <a href="qshortcut.html#key-prop">setKey</a>().</p> <h3 class="fn"><a name="QShortcut-2"></a>QShortcut::QShortcut ( const <a href="qkeysequence.html">QKeySequence</a> & <i>key</i>, <a href="qwidget.html">QWidget</a> * <i>parent</i>, const char * <i>member</i> = 0, const char * <i>ambiguousMember</i> = 0, <a href="qt.html#ShortcutContext-enum">Qt::ShortcutContext</a> <i>context</i> = Qt::WindowShortcut )</h3> <p>Constructs a <a href="qshortcut.html">QShortcut</a> object for the <i>parent</i> widget. The shortcut operates on its parent, listening for <a href="qshortcutevent.html">QShortcutEvent</a>s that match the <i>key</i> sequence. Depending on the ambiguity of the event, the shortcut will call the <i>member</i> function, or the <i>ambiguousMember</i> function, if the key press was in the shortcut's <i>context</i>.</p> <a name="//apple_ref/cpp/instm/QShortcut/~QShortcut"></a> <h3 class="fn"><a name="dtor.QShortcut"></a>QShortcut::~QShortcut ()</h3> <p>Destroys the shortcut.</p> <a name="//apple_ref/cpp/instm/QShortcut/activated"></a> <h3 class="fn"><a name="activated"></a>void QShortcut::activated () <tt> [signal]</tt></h3> <p>This signal is emitted when the user types the shortcut's key sequence.</p> <p>See also <a href="qshortcut.html#activatedAmbiguously">activatedAmbiguously</a>().</p> <a name="//apple_ref/cpp/instm/QShortcut/activatedAmbiguously"></a> <h3 class="fn"><a name="activatedAmbiguously"></a>void QShortcut::activatedAmbiguously () <tt> [signal]</tt></h3> <p>When a key sequence is being typed at the keyboard, it is said to be ambiguous as long as it matches the start of more than one shortcut.</p> <p>When a shortcut's key sequence is completed, activatedAmbiguously() is emitted if the key sequence is still ambiguous (i.e., it is the start of one or more other shortcuts). The <a href="qshortcut.html#activated">activated</a>() signal is not emitted in this case.</p> <p>See also <a href="qshortcut.html#activated">activated</a>().</p> <a name="//apple_ref/cpp/instm/QShortcut/id"></a> <h3 class="fn"><a name="id"></a>int QShortcut::id () const</h3> <p>Returns the shortcut's ID.</p> <p>See also <a href="qshortcutevent.html#shortcutId">QShortcutEvent::shortcutId</a>().</p> <a name="//apple_ref/cpp/instm/QShortcut/parentWidget"></a> <h3 class="fn"><a name="parentWidget"></a><a href="qwidget.html">QWidget</a> * QShortcut::parentWidget () const</h3> <p>Returns the shortcut's parent widget.</p> <p /><address><hr /><div align="center"> <table width="100%" cellspacing="0" border="0"><tr class="address"> <td width="40%" align="left">Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies)</td> <td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td> <td width="40%" align="right"><div align="right">Qt 4.6.3</div></td> </tr></table></div></address></body> </html>