<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QKeyEvent Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></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="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QKeyEvent Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QKeyEvent class describes a key event. <a href="#details">More...</a></p> <p>Inherits <a href="qinputevent.html">QInputEvent</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qkeyevent.html#QKeyEvent">__init__</a></b> (<i>self</i>, QEvent.Type <i>type</i>, int <i>key</i>, Qt.KeyboardModifiers <i>modifiers</i>, QString <i>text</i> = QString(), bool <i>autorep</i> = False, int <i>count</i> = 1)</li><li><div class="fn" /><b><a href="qkeyevent.html#QKeyEvent-2">__init__</a></b> (<i>self</i>, QKeyEvent)</li><li><div class="fn" />int <b><a href="qkeyevent.html#count">count</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qkeyevent.html#isAutoRepeat">isAutoRepeat</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qkeyevent.html#key">key</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qkeyevent.html#matches">matches</a></b> (<i>self</i>, QKeySequence.StandardKey <i>key</i>)</li><li><div class="fn" />Qt.KeyboardModifiers <b><a href="qkeyevent.html#modifiers">modifiers</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qkeyevent.html#nativeModifiers">nativeModifiers</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qkeyevent.html#nativeScanCode">nativeScanCode</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qkeyevent.html#nativeVirtualKey">nativeVirtualKey</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qkeyevent.html#text">text</a></b> (<i>self</i>)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />bool <b><a href="qkeyevent.html#__eq__">__eq__</a></b> (<i>self</i>, QKeySequence.StandardKey <i>key</i>)</li><li><div class="fn" /> <b><a href="qkeyevent.html#__len__">__len__</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qkeyevent.html#__ne__">__ne__</a></b> (<i>self</i>, QKeySequence.StandardKey <i>key</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QKeyEvent class describes a key event.</p> <p>Key events are sent to the widget with keyboard input focus when keys are pressed or released.</p> <p>A key event contains a special accept flag that indicates whether the receiver will handle the key event. You should call <a href="qevent.html#ignore">ignore</a>() if the key press or release event is not handled by your widget. A key event is propagated up the parent widget chain until a widget accepts it with <a href="qevent.html#accept">accept</a>() or an event filter consumes it. Key events for multimedia keys are ignored by default. You should call <a href="qevent.html#accept">accept</a>() if your widget handles those events.</p> <p>The QWidget.setEnable() function can be used to enable or disable mouse and keyboard events for a widget.</p> <p>The event handlers <a href="qwidget.html#keyPressEvent">QWidget.keyPressEvent</a>(), <a href="qwidget.html#keyReleaseEvent">QWidget.keyReleaseEvent</a>(), <a href="qgraphicsitem.html#keyPressEvent">QGraphicsItem.keyPressEvent</a>() and <a href="qgraphicsitem.html#keyReleaseEvent">QGraphicsItem.keyReleaseEvent</a>() receive key events.</p> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QKeyEvent" />QKeyEvent.__init__ (<i>self</i>, <a href="qevent.html#Type-enum">QEvent.Type</a> <i>type</i>, int <i>key</i>, <a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> <i>modifiers</i>, QString <i>text</i> = QString(), bool <i>autorep</i> = False, int <i>count</i> = 1)</h3><p>Constructs a key event object.</p> <p>The <i>type</i> parameter must be <a href="qevent.html#Type-enum">QEvent.KeyPress</a>, <a href="qevent.html#Type-enum">QEvent.KeyRelease</a>, or <a href="qevent.html#Type-enum">QEvent.ShortcutOverride</a>.</p> <p>Int <i>key</i> is the code for the <a href="qt.html#Key-enum">Qt.Key</a> that the event loop should listen for. If <i>key</i> is 0, the event is not a result of a known key; for example, it may be the result of a compose sequence or keyboard macro. The <i>modifiers</i> holds the keyboard modifiers, and the given <i>text</i> is the Unicode text that the key generated. If <i>autorep</i> is true, <a href="qkeyevent.html#isAutoRepeat">isAutoRepeat</a>() will be true. <i>count</i> is the number of keys involved in the event.</p> <h3 class="fn"><a name="QKeyEvent-2" />QKeyEvent.__init__ (<i>self</i>, <a href="qkeyevent.html">QKeyEvent</a>)</h3><h3 class="fn"><a name="count" />int QKeyEvent.count (<i>self</i>)</h3><p>Returns the number of keys involved in this event. If <a href="qkeyevent.html#text">text</a>() is not empty, this is simply the length of the string.</p> <p><b>See also</b> <a href="qt.html#WidgetAttribute-enum">Qt.WA_KeyCompression</a>.</p> <h3 class="fn"><a name="isAutoRepeat" />bool QKeyEvent.isAutoRepeat (<i>self</i>)</h3><p>Returns true if this event comes from an auto-repeating key; returns false if it comes from an initial key press.</p> <p>Note that if the event is a multiple-key compressed event that is partly due to auto-repeat, this function could return either true or false indeterminately.</p> <h3 class="fn"><a name="key" />int QKeyEvent.key (<i>self</i>)</h3><p>Returns the code of the key that was pressed or released.</p> <p>See <a href="qt.html#Key-enum">Qt.Key</a> for the list of keyboard codes. These codes are independent of the underlying window system. Note that this function does not distinguish between capital and non-capital letters, use the <a href="qkeyevent.html#text">text</a>() function (returning the Unicode text the key generated) for this purpose.</p> <p>A value of either 0 or <a href="qt.html#Key-enum">Qt.Key_unknown</a> means that the event is not the result of a known key; for example, it may be the result of a compose sequence, a keyboard macro, or due to key event compression.</p> <p><b>See also</b> <a href="qt.html#WidgetAttribute-enum">Qt.WA_KeyCompression</a>.</p> <h3 class="fn"><a name="matches" />bool QKeyEvent.matches (<i>self</i>, <a href="qkeysequence.html#StandardKey-enum">QKeySequence.StandardKey</a> <i>key</i>)</h3><p>Returns true if the key event matches the given standard <i>key</i>; otherwise returns false.</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="modifiers" /><a href="qt-keyboardmodifiers.html">Qt.KeyboardModifiers</a> QKeyEvent.modifiers (<i>self</i>)</h3><p>Returns the keyboard modifier flags that existed immediately after the event occurred.</p> <p><b>Warning:</b> This function cannot always be trusted. The user can confuse it by pressing both <b>Shift</b> keys simultaneously and releasing one of them, for example.</p> <p><b>See also</b> <a href="qapplication.html#keyboardModifiers">QApplication.keyboardModifiers</a>().</p> <h3 class="fn"><a name="nativeModifiers" />int QKeyEvent.nativeModifiers (<i>self</i>)</h3><p>Returns the native modifiers of a key event. If the key event does not contain this data 0 is returned.</p> <p>Note: The native modifiers may be 0, even if the key event contains extended information.</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="nativeScanCode" />int QKeyEvent.nativeScanCode (<i>self</i>)</h3><p>Returns the native scan code of the key event. If the key event does not contain this data 0 is returned.</p> <p>Note: The native scan code may be 0, even if the key event contains extended information.</p> <p>Note: On Mac OS/X, this function is not useful, because there is no way to get the scan code from Carbon or Cocoa. The function always returns 1 (or 0 in the case explained above).</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="nativeVirtualKey" />int QKeyEvent.nativeVirtualKey (<i>self</i>)</h3><p>Returns the native virtual key, or key sym of the key event. If the key event does not contain this data 0 is returned.</p> <p>Note: The native virtual key may be 0, even if the key event contains extended information.</p> <p>This function was introduced in Qt 4.2.</p> <h3 class="fn"><a name="text" />QString QKeyEvent.text (<i>self</i>)</h3><p>Returns the Unicode text that this key generated. The text returned can be an empty string in cases where modifier keys, such as Shift, Control, Alt, and Meta, are being pressed or released. In such cases <a href="qkeyevent.html#key">key</a>() will contain a valid value.</p> <p><b>See also</b> <a href="qt.html#WidgetAttribute-enum">Qt.WA_KeyCompression</a>.</p> <h3 class="fn"><a name="__eq__" />bool QKeyEvent.__eq__ (<i>self</i>, <a href="qkeysequence.html#StandardKey-enum">QKeySequence.StandardKey</a> <i>key</i>)</h3><h3 class="fn"><a name="__len__" /> QKeyEvent.__len__ (<i>self</i>)</h3><h3 class="fn"><a name="__ne__" />bool QKeyEvent.__ne__ (<i>self</i>, <a href="qkeysequence.html#StandardKey-enum">QKeySequence.StandardKey</a> <i>key</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>