QKeyEvent(3qt)
π QKeyEvent π
ok so bestie, we're in the Qt 3 manual pages, section 3qt, and today's main character is QKeyEvent β the class that describes a key event. yes, that kind of key event. the "user pressed a button and now your widget has to deal with it" kind. πΉβ¨
β¨ NAME β¨
QKeyEvent β describes a key event π
πΈ SYNOPSIS πΈ
#include <qevent.h>
Inherits QEvent.
π Public Members π
QKeyEvent ( Type type, int key, int ascii, int state, const QString &
text = QString::null, bool autorep = FALSE, ushort count = 1 )
int key () const
int ascii () const
ButtonState state () const
ButtonState stateAfter () const
bool isAccepted () const
QString text () const
bool isAutoRepeat () const
int count () const
void accept ()
void ignore ()
look at that little roster. they're all doing their jobs. we love to see it π«Ά
π¦ DESCRIPTION π¦
The QKeyEvent class contains β describes a key event. (yes, the original really does say both things in one breath, and honestly? relatable. it's giving "I contain multitudes.") π
Key events show up whenever a key gets pressed or released while a widget has keyboard input focus. so like, if your widget is the one everyone's listening to, it hears the keys. π
A key event carries a special accept flag that says whether the receiver actually wants this key event or not. If your widget does not handle the key press or release, you should call QKeyEvent::ignore(). What happens then? The event gets propagated up the parent widget chain, going from parent to parent, until some widget accepts it with QKeyEvent::accept() β or until an event filter straight up consumes it. π
Key events for multi media keys are ignored by default. So if your widget wants those, you gotta call QKeyEvent::accept() yourself. no cap.
Also, QWidget::setEnable() is the function you use to enable or disable mouse and keyboard events for a widget. π±οΈβ¨οΈ
And the event handlers that actually receive key events are QWidget::keyPressEvent() and QWidget::keyReleaseEvent(). those are the ones catching the vibes.
See also: QFocusEvent, QWidget::grabKeyboard(), and Event Classes. π
π MEMBER FUNCTION DOCUMENTATION π
π QKeyEvent::QKeyEvent ( Type type, int key, int ascii, int state, const QString & text = QString::null, bool autorep = FALSE, ushort count = 1 )
Constructs a key event object. new object, who dis. β¨
typeβ has to beQEvent::KeyPressorQEvent::KeyRelease. those are the only two options, bestie, no negotiating.keyβ if this is0, the event isn't the result of a known key. like, it could be the result of a compose sequence or a keyboard macro. mystery key energy. πasciiβ the ASCII code of the key that was pressed or released.stateβ holds the keyboard modifiers.textβ the Unicode text that the key generated.autorepβ if it'sTRUE, thenisAutoRepeat()will beTRUE.countβ the number of single keys.
The accept flag gets set to TRUE. π
π void QKeyEvent::accept ()
Sets the accept flag of the key event object. slay.
Setting the accept parameter means the receiver of the event wants the key event. Unwanted key events get sent to the parent widget instead. π«Ά
The accept flag is set by default.
See also: ignore().
β int QKeyEvent::ascii () const
Returns the ASCII code of the key that was pressed or released. That said β we recommend using text() instead. consider this the older sibling that's still cool but like, text() is the moment. β¨
See also: text().
Example: picture/picture.cpp.
π int QKeyEvent::count () const
Returns the number of single keys for this event. And if text() isn't empty? Then it's simply the length of the string. math is math. π
See also: QWidget::setKeyCompression().
π void QKeyEvent::ignore ()
Clears the accept flag parameter of the key event object.
Clearing the accept parameter means the event receiver does not want the key event. Unwanted key events get sent to the parent widget. bye bestie, off it goes up the chain. π¦
The accept flag is set by default.
See also: accept().
πΈ bool QKeyEvent::isAccepted () const
Returns TRUE if the receiver of the event wants to keep the key; otherwise returns FALSE. it's a vibe check, basically. β
β
π§ bool QKeyEvent::isAutoRepeat () const
Returns TRUE if this event comes from an auto-repeating key, and FALSE if it comes from an initial key press.
Note: if the event is a multiple-key compressed event that's partly due to auto-repeat, this function could return eitherTRUEorFALSEindeterminately. it's not being shady on purpose, it just genuinely doesn't know. π
π₯ int QKeyEvent::key () const
Returns the code of the key that was pressed or released.
For the full list of keyboard codes, see Qt::Key. these codes are independent of the underlying window system β iconic behaviour honestly. π
A value of either 0 or Key_unknown means the event is not the result of a known key. it could be the result of a compose sequence, or a keyboard macro, or it could be due to key event compression. so many possibilities, so little certainty. π«
See also: QWidget::setKeyCompression().
Example: fileiconview/qfileiconview.cpp.
π ButtonState QKeyEvent::state () const
Returns the keyboard modifier flags that existed immediately before the event occurred.
The returned value is ShiftButton, ControlButton, AltButton and MetaButton all OR'ed together. the whole squad, together. π«
See also: stateAfter().
Example: fileiconview/qfileiconview.cpp.
π ButtonState QKeyEvent::stateAfter () const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Warning: This function cannot be trusted. π© not "usually fine," not "mostly reliable" β cannot be trusted. proceed accordingly, bestie.
See also: state().
π QString QKeyEvent::text () const
Returns the Unicode text that this key generated. The text returned might be empty β that's what happens when you press or release modifying keys like Shift, Control, Alt and Meta. and in those cases? key() will still contain a valid value, so you're not left hanging. π
See also: QWidget::setKeyCompression().
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
βοΈ AUTHOR βοΈ
Generated automatically from the source code. (no human author to thank, it just spawned. π€β¨)
π BUGS π
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. π
The definitive Qt documentation is provided in HTML format; it's located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. π
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qkeyevent.3qt) and the Qt version (3.3.8). pls include those, they need them, don't make them guess. π₯Ί
and that's the whole page bestie!! brought to you by Trolltech AS, dated 2 February 2007, sitting pretty in the Qt 3.3.8 era β and the manual page name, for the record, is QKeyEvent(3qt). stay focused, accept your key events, and never trust stateAfter(). periodt π
β¨π
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms