QKeyEvent(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

πŸ’– 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 be QEvent::KeyPress or QEvent::KeyRelease. those are the only two options, bestie, no negotiating.
  • key β€” if this is 0, 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's TRUE, then isAutoRepeat() will be TRUE.
  • 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 either TRUE or FALSE indeterminately. 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 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