1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
44 #include "private/qguiapplication_p.h"
45 #include "qpa/qplatformintegration.h"
46 #include "qpa/qplatformdrag.h"
47 #include "private/qevent_p.h"
48 #include "private/qkeysequence_p.h"
50 #include "qmimedata.h"
51 #include "private/qdnd_p.h"
63 \brief The QInputEvent class is the base class for events that
70 QInputEvent::QInputEvent(Type type, Qt::KeyboardModifiers modifiers)
71 : QEvent(type), modState(modifiers), ts(0)
77 QInputEvent::~QInputEvent()
82 \fn Qt::KeyboardModifiers QInputEvent::modifiers() const
84 Returns the keyboard modifier flags that existed immediately
85 before the event occurred.
87 \sa QApplication::keyboardModifiers()
90 /*! \fn void QInputEvent::setModifiers(Qt::KeyboardModifiers modifiers)
94 Sets the keyboard modifiers flags for this event.
98 \fn ulong QInputEvent::timestamp() const
100 Returns the window system's timestamp for this event.
103 /*! \fn void QInputEvent::setTimestamp(ulong atimestamp)
107 Sets the timestamp for this event.
114 \brief The QMouseEvent class contains parameters that describe a mouse event.
116 Mouse events occur when a mouse button is pressed or released
117 inside a widget, or when the mouse cursor is moved.
119 Mouse move events will occur only when a mouse button is pressed
120 down, unless mouse tracking has been enabled with
121 QWidget::setMouseTracking().
123 Qt automatically grabs the mouse when a mouse button is pressed
124 inside a widget; the widget will continue to receive mouse events
125 until the last mouse button is released.
127 A mouse event contains a special accept flag that indicates
128 whether the receiver wants the event. You should call ignore() if
129 the mouse event is not handled by your widget. A mouse event is
130 propagated up the parent widget chain until a widget accepts it
131 with accept(), or an event filter consumes it.
133 \note If a mouse event is propagated to a \l{QWidget}{widget} for
134 which Qt::WA_NoMousePropagation has been set, that mouse event
135 will not be propagated further up the parent widget chain.
137 The state of the keyboard modifier keys can be found by calling the
138 \l{QInputEvent::modifiers()}{modifiers()} function, inherited from
141 The functions pos(), x(), and y() give the cursor position
142 relative to the widget that receives the mouse event. If you
143 move the widget as a result of the mouse event, use the global
144 position returned by globalPos() to avoid a shaking motion.
146 The QWidget::setEnabled() function can be used to enable or
147 disable mouse and keyboard events for a widget.
149 Reimplement the QWidget event handlers, QWidget::mousePressEvent(),
150 QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(),
151 and QWidget::mouseMoveEvent() to receive mouse events in your own
154 \sa QWidget::setMouseTracking(), QWidget::grabMouse(),
159 Constructs a mouse event object.
161 The \a type parameter must be one of QEvent::MouseButtonPress,
162 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
163 or QEvent::MouseMove.
165 The \a localPos is the mouse cursor's position relative to the
166 receiving widget or item. The window position is set to the same value
168 The \a button that caused the event is given as a value from
169 the Qt::MouseButton enum. If the event \a type is
170 \l MouseMove, the appropriate button for this event is Qt::NoButton.
171 The mouse and keyboard states at the time of the event are specified by
172 \a buttons and \a modifiers.
174 The screenPos() is initialized to QCursor::pos(), which may not
175 be appropriate. Use the other constructor to specify the global
178 QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
179 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
180 : QInputEvent(type, modifiers), l(localPos), w(localPos), b(button), mouseState(buttons), caps(0)
187 Constructs a mouse event object.
189 The \a type parameter must be QEvent::MouseButtonPress,
190 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
191 or QEvent::MouseMove.
193 The \a localPos is the mouse cursor's position relative to the
194 receiving widget or item. The cursor's position in screen coordinates is
195 specified by \a screenPos. The window position is set to the same value
196 as \a localPos. The \a button that caused the event is
197 given as a value from the \l Qt::MouseButton enum. If the event \a
198 type is \l MouseMove, the appropriate button for this event is
199 Qt::NoButton. \a buttons is the state of all buttons at the
200 time of the event, \a modifiers the state of all keyboard
204 QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &screenPos,
205 Qt::MouseButton button, Qt::MouseButtons buttons,
206 Qt::KeyboardModifiers modifiers)
207 : QInputEvent(type, modifiers), l(localPos), w(localPos), s(screenPos), b(button), mouseState(buttons), caps(0)
211 Constructs a mouse event object.
213 The \a type parameter must be QEvent::MouseButtonPress,
214 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
215 or QEvent::MouseMove.
217 The points \a localPos, \a windowPos and \a screenPos specify the
218 mouse cursor's position relative to the receiving widget or item,
219 window, and screen, respectively.
221 The \a button that caused the event is
222 given as a value from the \l Qt::MouseButton enum. If the event \a
223 type is \l MouseMove, the appropriate button for this event is
224 Qt::NoButton. \a buttons is the state of all buttons at the
225 time of the event, \a modifiers the state of all keyboard
229 QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos,
230 Qt::MouseButton button, Qt::MouseButtons buttons,
231 Qt::KeyboardModifiers modifiers)
232 : QInputEvent(type, modifiers), l(localPos), w(windowPos), s(screenPos), b(button), mouseState(buttons), caps(0)
238 QMouseEvent::~QMouseEvent()
244 \fn QPointF QMouseEvent::localPos() const
248 Returns the position of the mouse cursor as a QPointF, relative to the
249 widget or item that received the event.
251 If you move the widget as a result of the mouse event, use the
252 screen position returned by screenPos() to avoid a shaking
255 \sa x(), y(), windowPos(), screenPos()
259 \fn QPointF QMouseEvent::windowPos() const
263 Returns the position of the mouse cursor as a QPointF, relative to the
264 window that received the event.
266 If you move the widget as a result of the mouse event, use the
267 global position returned by globalPos() to avoid a shaking
270 \sa x(), y(), pos(), localPos(), screenPos()
274 \fn QPointF QMouseEvent::screenPos() const
278 Returns the position of the mouse cursor as a QPointF, relative to the
279 screen that received the event.
281 \sa x(), y(), pos(), localPos(), screenPos()
285 \fn QPoint QMouseEvent::pos() const
287 Returns the position of the mouse cursor, relative to the widget
288 that received the event.
290 If you move the widget as a result of the mouse event, use the
291 global position returned by globalPos() to avoid a shaking
294 \sa x(), y(), globalPos()
298 \fn QPoint QMouseEvent::globalPos() const
300 Returns the global position of the mouse cursor \e{at the time
301 of the event}. This is important on asynchronous window systems
302 like X11. Whenever you move your widgets around in response to
303 mouse events, globalPos() may differ a lot from the current
304 pointer position QCursor::pos(), and from
305 QWidget::mapToGlobal(pos()).
307 \sa globalX(), globalY()
311 \fn int QMouseEvent::x() const
313 Returns the x position of the mouse cursor, relative to the
314 widget that received the event.
320 \fn int QMouseEvent::y() const
322 Returns the y position of the mouse cursor, relative to the
323 widget that received the event.
329 \fn int QMouseEvent::globalX() const
331 Returns the global x position of the mouse cursor at the time of
334 \sa globalY(), globalPos()
338 \fn int QMouseEvent::globalY() const
340 Returns the global y position of the mouse cursor at the time of
343 \sa globalX(), globalPos()
347 \fn Qt::MouseButton QMouseEvent::button() const
349 Returns the button that caused the event.
351 Note that the returned value is always Qt::NoButton for mouse
354 \sa buttons(), Qt::MouseButton
358 \fn Qt::MouseButton QMouseEvent::buttons() const
360 Returns the button state when the event was generated. The button
361 state is a combination of Qt::LeftButton, Qt::RightButton,
362 Qt::MidButton using the OR operator. For mouse move events,
363 this is all buttons that are pressed down. For mouse press and
364 double click events this includes the button that caused the
365 event. For mouse release events this excludes the button that
368 \sa button(), Qt::MouseButton
372 \fn QPointF QMouseEvent::posF() const
375 Use localPos() instead.
382 \brief The QHoverEvent class contains parameters that describe a mouse event.
384 Mouse events occur when a mouse cursor is moved into, out of, or within a
385 widget, and if the widget has the Qt::WA_Hover attribute.
387 The function pos() gives the current cursor position, while oldPos() gives
388 the old mouse position.
390 There are a few similarities between the events QEvent::HoverEnter
391 and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave.
392 However, they are slightly different because we do an update() in the event
393 handler of HoverEnter and HoverLeave.
395 QEvent::HoverMove is also slightly different from QEvent::MouseMove. Let us
396 consider a top-level window A containing a child B which in turn contains a
397 child C (all with mouse tracking enabled):
399 \image hoverevents.png
401 Now, if you move the cursor from the top to the bottom in the middle of A,
402 you will get the following QEvent::MouseMove events:
410 You will get the same events for QEvent::HoverMove, except that the event
411 always propagates to the top-level regardless whether the event is accepted
412 or not. It will only stop propagating with the Qt::WA_NoMousePropagation
415 In this case the events will occur in the following way:
419 \li A::HoverMove, B::HoverMove
420 \li A::HoverMove, B::HoverMove, C::HoverMove
426 \fn QPoint QHoverEvent::pos() const
428 Returns the position of the mouse cursor, relative to the widget
429 that received the event.
431 On QEvent::HoverLeave events, this position will always be
438 \fn QPoint QHoverEvent::oldPos() const
440 Returns the previous position of the mouse cursor, relative to the widget
441 that received the event. If there is no previous position, oldPos() will
442 return the same position as pos().
444 On QEvent::HoverEnter events, this position will always be
451 \fn const QPointF &QHoverEvent::posF() const
453 Returns the position of the mouse cursor, relative to the widget
454 that received the event.
456 On QEvent::HoverLeave events, this position will always be
463 \fn const QPointF &QHoverEvent::oldPosF() const
465 Returns the previous position of the mouse cursor, relative to the widget
466 that received the event. If there is no previous position, oldPosF() will
467 return the same position as posF().
469 On QEvent::HoverEnter events, this position will always be
476 Constructs a hover event object.
478 The \a type parameter must be QEvent::HoverEnter,
479 QEvent::HoverLeave, or QEvent::HoverMove.
481 The \a pos is the current mouse cursor's position relative to the
482 receiving widget, while \a oldPos is its previous such position.
483 \a modifiers hold the state of all keyboard modifiers at the time
486 QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers)
487 : QInputEvent(type, modifiers), p(pos), op(oldPos)
494 QHoverEvent::~QHoverEvent()
501 \brief The QWheelEvent class contains parameters that describe a wheel event.
506 Wheel events are sent to the widget under the mouse cursor, but
507 if that widget does not handle the event they are sent to the
508 focus widget. Wheel events are generated for both mouse wheels
509 and trackpad scroll gestures. There are two ways to read the
510 wheel event delta: angleDelta() returns the delta in wheel
511 degrees. This value is always provided. pixelDelta() returns
512 the delta in screen pixels and is available on platforms that
513 have high-resolution trackpads, such as Mac OS X.
515 The functions pos() and globalPos() return the mouse cursor's
516 location at the time of the event.
518 A wheel event contains a special accept flag that indicates
519 whether the receiver wants the event. You should call ignore() if
520 you do not handle the wheel event; this ensures that it will be
521 sent to the parent widget.
523 The QWidget::setEnabled() function can be used to enable or
524 disable mouse and keyboard events for a widget.
526 The event handler QWidget::wheelEvent() receives wheel events.
528 \sa QMouseEvent, QWidget::grabMouse()
532 \fn Qt::MouseButtons QWheelEvent::buttons() const
534 Returns the mouse state when the event occurred.
538 \fn Qt::Orientation QWheelEvent::orientation() const
541 Returns the wheel's orientation.
543 Use angleDelta() instead.
548 Constructs a wheel event object.
550 Use the constructor taking \e angleDelta and \e pixelDelta QPoints instead.
552 The position, \a pos, is the location of the mouse cursor within
553 the widget. The globalPos() is initialized to QCursor::pos()
554 which is usually, but not always, correct.
555 Use the other constructor if you need to specify the global
558 The \a buttons describe the state of the mouse buttons at the time
559 of the event, \a delta contains the rotation distance,
560 \a modifiers holds the keyboard modifier flags at the time of the
561 event, and \a orient holds the wheel's orientation.
563 \sa pos(), pixelDelta(), angleDelta(), state()
565 #ifndef QT_NO_WHEELEVENT
566 QWheelEvent::QWheelEvent(const QPointF &pos, int delta,
567 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
568 Qt::Orientation orient)
569 : QInputEvent(Wheel, modifiers), p(pos), qt4D(delta), qt4O(orient), mouseState(buttons)
577 QWheelEvent::~QWheelEvent()
583 Constructs a wheel event object.
585 Use the constructor taking \e angleDelta and \e pixelDelta QPoints instead.
587 The \a pos provides the location of the mouse cursor
588 within the widget. The position in global coordinates is specified
589 by \a globalPos. \a delta contains the rotation distance, \a modifiers
590 holds the keyboard modifier flags at the time of the event, and
591 \a orient holds the wheel's orientation.
594 \sa pos(), pixelDelta(), angleDelta(), state()
596 QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta,
597 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
598 Qt::Orientation orient)
599 : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), qt4D(delta), qt4O(orient), mouseState(buttons)
603 Constructs a wheel event object.
605 The \a pos provides the location of the mouse cursor
606 within the window. The position in global coordinates is specified
609 \a pixelDelta contains the scrolling distance in pixels on screen, while
610 \a angleDelta contains the wheel rotation distance. \a pixelDelta is
611 optional and can be null.
613 The mouse and keyboard states at the time of the event are specified by
614 \a buttons and \a modifiers.
616 For backwards compatibility, the event can also hold monodirectional wheel
617 event data: \a qt4Delta specifies the rotation, and \a qt4Orientation the
620 \sa posF(), globalPosF(), angleDelta(), pixelDelta()
623 QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
624 QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
625 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
626 : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta),
627 angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons)
631 #endif // QT_NO_WHEELEVENT
634 \fn QPoint QWheelEvent::pixelDelta() const
636 Returns the scrolling distance in pixels on screen. This value is
637 provided on platforms that support high-resolution pixel-based
638 delta values, such as Mac OS X. The value should be used directly
639 to scroll content on screen.
643 \snippet code/src_gui_kernel_qevent.cpp 0
647 \fn QPoint QWheelEvent::angleDelta() const
649 Returns the distance that the wheel is rotated, in eighths of a
650 degree. A positive value indicates that the wheel was rotated
651 forwards away from the user; a negative value indicates that the
652 wheel was rotated backwards toward the user.
654 Most mouse types work in steps of 15 degrees, in which case the
655 delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
657 However, some mice have finer-resolution wheels and send delta values
658 that are less than 120 units (less than 15 degrees). To support this
659 possibility, you can either cumulatively add the delta values from events
660 until the value of 120 is reached, then scroll the widget, or you can
661 partially scroll the widget in response to each wheel event.
665 \snippet code/src_gui_kernel_qevent.cpp 0
669 \fn int QWheelEvent::delta() const
672 This function has been deprecated, use pixelDelta() or angleDelta() instead.
676 \fn QPoint QWheelEvent::pos() const
678 Returns the position of the mouse cursor relative to the widget
679 that received the event.
681 If you move your widgets around in response to mouse events,
682 use globalPos() instead of this function.
684 \sa x(), y(), globalPos()
688 \fn int QWheelEvent::x() const
690 Returns the x position of the mouse cursor, relative to the
691 widget that received the event.
697 \fn int QWheelEvent::y() const
699 Returns the y position of the mouse cursor, relative to the
700 widget that received the event.
707 \fn QPoint QWheelEvent::globalPos() const
709 Returns the global position of the mouse pointer \e{at the time
710 of the event}. This is important on asynchronous window systems
711 such as X11; whenever you move your widgets around in response to
712 mouse events, globalPos() can differ a lot from the current
713 cursor position returned by QCursor::pos().
715 \sa globalX(), globalY()
719 \fn int QWheelEvent::globalX() const
721 Returns the global x position of the mouse cursor at the time of
724 \sa globalY(), globalPos()
728 \fn int QWheelEvent::globalY() const
730 Returns the global y position of the mouse cursor at the time of
733 \sa globalX(), globalPos()
737 \fn const QPointF &QWheelEvent::posF() const
739 Returns the position of the mouse cursor relative to the widget
740 that received the event.
742 If you move your widgets around in response to mouse events,
743 use globalPosF() instead of this function.
749 \fn const QPointF &QWheelEvent::globalPosF() const
751 Returns the global position of the mouse pointer \e{at the time
752 of the event}. This is important on asynchronous window systems
753 such as X11; whenever you move your widgets around in response to
754 mouse events, globalPosF() can differ a lot from the current
755 cursor position returned by QCursor::pos().
763 \brief The QKeyEvent class describes a key event.
767 Key events are sent to the widget with keyboard input focus
768 when keys are pressed or released.
770 A key event contains a special accept flag that indicates whether
771 the receiver will handle the key event. You should call ignore()
772 if the key press or release event is not handled by your widget.
773 A key event is propagated up the parent widget chain until a
774 widget accepts it with accept() or an event filter consumes it.
775 Key events for multimedia keys are ignored by default. You should
776 call accept() if your widget handles those events.
778 The QWidget::setEnable() function can be used to enable or disable
779 mouse and keyboard events for a widget.
781 The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(),
782 QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent()
785 \sa QFocusEvent, QWidget::grabKeyboard()
789 Constructs a key event object.
791 The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
792 or QEvent::ShortcutOverride.
794 Int \a key is the code for the Qt::Key that the event loop should listen
795 for. If \a key is 0, the event is not a result of a known key; for
796 example, it may be the result of a compose sequence or keyboard macro.
797 The \a modifiers holds the keyboard modifiers, and the given \a text
798 is the Unicode text that the key generated. If \a autorep is true,
799 isAutoRepeat() will be true. \a count is the number of keys involved
802 QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
803 bool autorep, ushort count)
804 : QInputEvent(type, modifiers), txt(text), k(key),
805 nScanCode(0), nVirtualKey(0), nModifiers(0),
806 c(count), autor(autorep)
811 Constructs a key event object.
813 The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
814 or QEvent::ShortcutOverride.
816 Int \a key is the code for the Qt::Key that the event loop should listen
817 for. If \a key is 0, the event is not a result of a known key; for
818 example, it may be the result of a compose sequence or keyboard macro.
819 The \a modifiers holds the keyboard modifiers, and the given \a text
820 is the Unicode text that the key generated. If \a autorep is true,
821 isAutoRepeat() will be true. \a count is the number of keys involved
824 In addition to the normal key event data, also contains \a nativeScanCode,
825 \a nativeVirtualKey and \a nativeModifiers. This extra data is used by the
826 shortcut system, to determine which shortcuts to trigger.
828 QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
829 quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
830 const QString &text, bool autorep, ushort count)
831 : QInputEvent(type, modifiers), txt(text), k(key),
832 nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers),
833 c(count), autor(autorep)
841 QKeyEvent::~QKeyEvent()
846 \fn QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString& text, bool autorep, ushort count)
851 \fn bool QKeyEvent::hasExtendedInfo() const
856 \fn quint32 QKeyEvent::nativeScanCode() const
859 Returns the native scan code of the key event. If the key event
860 does not contain this data 0 is returned.
862 Note: The native scan code may be 0, even if the key event contains
863 extended information.
865 Note: On Mac OS/X, this function is not useful, because there is no
866 way to get the scan code from Carbon or Cocoa. The function always
867 returns 1 (or 0 in the case explained above).
871 \fn quint32 QKeyEvent::nativeVirtualKey() const
874 Returns the native virtual key, or key sym of the key event.
875 If the key event does not contain this data 0 is returned.
877 Note: The native virtual key may be 0, even if the key event contains extended information.
881 \fn quint32 QKeyEvent::nativeModifiers() const
884 Returns the native modifiers of a key event.
885 If the key event does not contain this data 0 is returned.
887 Note: The native modifiers may be 0, even if the key event contains extended information.
891 \fn int QKeyEvent::key() const
893 Returns the code of the key that was pressed or released.
895 See \l Qt::Key for the list of keyboard codes. These codes are
896 independent of the underlying window system. Note that this
897 function does not distinguish between capital and non-capital
898 letters, use the text() function (returning the Unicode text the
899 key generated) for this purpose.
901 A value of either 0 or Qt::Key_unknown means that the event is not
902 the result of a known key; for example, it may be the result of
903 a compose sequence, a keyboard macro, or due to key event
906 \sa Qt::WA_KeyCompression
910 \fn QString QKeyEvent::text() const
912 Returns the Unicode text that this key generated. The text
913 returned can be an empty string in cases
914 where modifier keys, such as Shift, Control, Alt, and Meta,
915 are being pressed or released. In such cases key() will contain
918 \sa Qt::WA_KeyCompression
922 Returns the keyboard modifier flags that existed immediately
923 after the event occurred.
925 \warning This function cannot always be trusted. The user can
926 confuse it by pressing both \uicontrol{Shift} keys simultaneously and
927 releasing one of them, for example.
929 \sa QApplication::keyboardModifiers()
931 //###### We must check with XGetModifierMapping
932 Qt::KeyboardModifiers QKeyEvent::modifiers() const
934 if (key() == Qt::Key_Shift)
935 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ShiftModifier);
936 if (key() == Qt::Key_Control)
937 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ControlModifier);
938 if (key() == Qt::Key_Alt)
939 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::AltModifier);
940 if (key() == Qt::Key_Meta)
941 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::MetaModifier);
942 return QInputEvent::modifiers();
945 #ifndef QT_NO_SHORTCUT
947 \fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const
950 Returns true if the key event matches the given standard \a key;
951 otherwise returns false.
953 bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const
955 uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier); //The keypad modifier should not make a difference
956 const uint platform = QKeySequencePrivate::currentKeyPlatforms();
959 uint N = QKeySequencePrivate::numberOfKeyBindings;
963 while (first <= last) {
964 int mid = (first + last) / 2;
965 QKeyBinding midVal = QKeySequencePrivate::keyBindings[mid];
967 if (searchkey > midVal.shortcut){
968 first = mid + 1; // Search in top half
970 else if (searchkey < midVal.shortcut){
971 last = mid - 1; // Search in bottom half
974 //found correct shortcut value, now we must check for platform match
975 if ((midVal.platform & platform) && (midVal.standardKey == matchKey)) {
977 } else { //We may have several equal values for different platforms, so we must search in both directions
980 for ( unsigned int i = mid + 1 ; i < N - 1 ; ++i) {
981 QKeyBinding current = QKeySequencePrivate::keyBindings[i];
982 if (current.shortcut != searchkey)
984 else if (current.platform & platform && current.standardKey == matchKey)
989 for ( int i = mid - 1 ; i >= 0 ; --i) {
990 QKeyBinding current = QKeySequencePrivate::keyBindings[i];
991 if (current.shortcut != searchkey)
993 else if (current.platform & platform && current.standardKey == matchKey)
996 return false; //we could not find it among the matching keySequences
1000 return false; //we could not find matching keySequences at all
1002 #endif // QT_NO_SHORTCUT
1006 \fn bool QKeyEvent::isAutoRepeat() const
1008 Returns true if this event comes from an auto-repeating key;
1009 returns false if it comes from an initial key press.
1011 Note that if the event is a multiple-key compressed event that is
1012 partly due to auto-repeat, this function could return either true
1013 or false indeterminately.
1017 \fn int QKeyEvent::count() const
1019 Returns the number of keys involved in this event. If text()
1020 is not empty, this is simply the length of the string.
1022 \sa Qt::WA_KeyCompression
1027 \brief The QFocusEvent class contains event parameters for widget focus
1033 Focus events are sent to widgets when the keyboard input focus
1034 changes. Focus events occur due to mouse actions, key presses
1035 (such as \uicontrol{Tab} or \uicontrol{Backtab}), the window system, popup
1036 menus, keyboard shortcuts, or other application-specific reasons.
1037 The reason for a particular focus event is returned by reason()
1038 in the appropriate event handler.
1040 The event handlers QWidget::focusInEvent(),
1041 QWidget::focusOutEvent(), QGraphicsItem::focusInEvent and
1042 QGraphicsItem::focusOutEvent() receive focus events.
1044 \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus}
1048 Constructs a focus event object.
1050 The \a type parameter must be either QEvent::FocusIn or
1051 QEvent::FocusOut. The \a reason describes the cause of the change
1054 QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason)
1055 : QEvent(type), m_reason(reason)
1061 QFocusEvent::~QFocusEvent()
1066 Returns the reason for this focus event.
1068 Qt::FocusReason QFocusEvent::reason() const
1074 \fn bool QFocusEvent::gotFocus() const
1076 Returns true if type() is QEvent::FocusIn; otherwise returns
1081 \fn bool QFocusEvent::lostFocus() const
1083 Returns true if type() is QEvent::FocusOut; otherwise returns
1090 \brief The QPaintEvent class contains event parameters for paint events.
1095 Paint events are sent to widgets that need to update themselves,
1096 for instance when part of a widget is exposed because a covering
1099 The event contains a region() that needs to be updated, and a
1100 rect() that is the bounding rectangle of that region. Both are
1101 provided because many widgets can't make much use of region(),
1102 and rect() can be much faster than region().boundingRect().
1104 \section1 Automatic Clipping
1106 Painting is clipped to region() during the processing of a paint
1107 event. This clipping is performed by Qt's paint system and is
1108 independent of any clipping that may be applied to a QPainter used to
1109 draw on the paint device.
1111 As a result, the value returned by QPainter::clipRegion() on
1112 a newly-constructed QPainter will not reflect the clip region that is
1113 used by the paint system.
1115 \sa QPainter, QWidget::update(), QWidget::repaint(),
1116 QWidget::paintEvent()
1120 Constructs a paint event object with the region that needs to
1121 be updated. The region is specified by \a paintRegion.
1123 QPaintEvent::QPaintEvent(const QRegion& paintRegion)
1124 : QEvent(Paint), m_rect(paintRegion.boundingRect()), m_region(paintRegion), m_erased(false)
1128 Constructs a paint event object with the rectangle that needs
1129 to be updated. The region is specified by \a paintRect.
1131 QPaintEvent::QPaintEvent(const QRect &paintRect)
1132 : QEvent(Paint), m_rect(paintRect),m_region(paintRect), m_erased(false)
1139 QPaintEvent::~QPaintEvent()
1144 \fn const QRect &QPaintEvent::rect() const
1146 Returns the rectangle that needs to be updated.
1148 \sa region(), QPainter::setClipRect()
1152 \fn const QRegion &QPaintEvent::region() const
1154 Returns the region that needs to be updated.
1156 \sa rect(), QPainter::setClipRegion()
1162 \brief The QMoveEvent class contains event parameters for move events.
1167 Move events are sent to widgets that have been moved to a new
1168 position relative to their parent.
1170 The event handler QWidget::moveEvent() receives move events.
1172 \sa QWidget::move(), QWidget::setGeometry()
1176 Constructs a move event with the new and old widget positions,
1177 \a pos and \a oldPos respectively.
1179 QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos)
1180 : QEvent(Move), p(pos), oldp(oldPos)
1186 QMoveEvent::~QMoveEvent()
1191 \fn const QPoint &QMoveEvent::pos() const
1193 Returns the new position of the widget. This excludes the window
1194 frame for top level widgets.
1198 \fn const QPoint &QMoveEvent::oldPos() const
1200 Returns the old position of the widget.
1206 \brief The QExposeEvent class contains event parameters for expose events.
1211 Expose events are sent to windows when an area of the window is invalidated
1212 or window visibility in the windowing system changes.
1214 The event handler QWindow::exposeEvent() receives expose events.
1218 Constructs an expose event for the given \a exposeRegion.
1220 QExposeEvent::QExposeEvent(const QRegion &exposeRegion)
1229 QExposeEvent::~QExposeEvent()
1234 \fn const QRegion &QExposeEvent::region() const
1236 Returns the window area that has been exposed.
1241 \brief The QResizeEvent class contains event parameters for resize events.
1246 Resize events are sent to widgets that have been resized.
1248 The event handler QWidget::resizeEvent() receives resize events.
1250 \sa QWidget::resize(), QWidget::setGeometry()
1254 Constructs a resize event with the new and old widget sizes, \a
1255 size and \a oldSize respectively.
1257 QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
1258 : QEvent(Resize), s(size), olds(oldSize)
1264 QResizeEvent::~QResizeEvent()
1269 \fn const QSize &QResizeEvent::size() const
1271 Returns the new size of the widget. This is the same as
1276 \fn const QSize &QResizeEvent::oldSize() const
1278 Returns the old size of the widget.
1284 \brief The QCloseEvent class contains parameters that describe a close event.
1289 Close events are sent to widgets that the user wants to close,
1290 usually by choosing "Close" from the window menu, or by clicking
1291 the \uicontrol{X} title bar button. They are also sent when you call
1292 QWidget::close() to close a widget programmatically.
1294 Close events contain a flag that indicates whether the receiver
1295 wants the widget to be closed or not. When a widget accepts the
1296 close event, it is hidden (and destroyed if it was created with
1297 the Qt::WA_DeleteOnClose flag). If it refuses to accept the close
1298 event nothing happens. (Under X11 it is possible that the window
1299 manager will forcibly close the window; but at the time of writing
1300 we are not aware of any window manager that does this.)
1302 The event handler QWidget::closeEvent() receives close events. The
1303 default implementation of this event handler accepts the close
1304 event. If you do not want your widget to be hidden, or want some
1305 special handing, you should reimplement the event handler and
1308 The \l{mainwindows/application#close event handler}{closeEvent() in the
1309 Application example} shows a close event handler that
1310 asks whether to save a document before closing.
1312 If you want the widget to be deleted when it is closed, create it
1313 with the Qt::WA_DeleteOnClose flag. This is very useful for
1314 independent top-level windows in a multi-window application.
1316 \l{QObject}s emits the \l{QObject::destroyed()}{destroyed()}
1317 signal when they are deleted.
1319 If the last top-level window is closed, the
1320 QApplication::lastWindowClosed() signal is emitted.
1322 The isAccepted() function returns true if the event's receiver has
1323 agreed to close the widget; call accept() to agree to close the
1324 widget and call ignore() if the receiver of this event does not
1325 want the widget to be closed.
1327 \sa QWidget::close(), QWidget::hide(), QObject::destroyed(),
1328 QCoreApplication::exec(), QCoreApplication::quit(),
1329 QApplication::lastWindowClosed()
1333 Constructs a close event object.
1337 QCloseEvent::QCloseEvent()
1343 QCloseEvent::~QCloseEvent()
1348 \class QIconDragEvent
1349 \brief The QIconDragEvent class indicates that a main icon drag has begun.
1354 Icon drag events are sent to widgets when the main icon of a window
1355 has been dragged away. On Mac OS X, this happens when the proxy
1356 icon of a window is dragged off the title bar.
1358 It is normal to begin using drag and drop in response to this
1361 \sa {Drag and Drop}, QMimeData, QDrag
1365 Constructs an icon drag event object with the accept flag set to
1370 QIconDragEvent::QIconDragEvent()
1375 QIconDragEvent::~QIconDragEvent()
1380 \class QContextMenuEvent
1381 \brief The QContextMenuEvent class contains parameters that describe a context menu event.
1386 Context menu events are sent to widgets when a user performs
1387 an action associated with opening a context menu.
1388 The actions required to open context menus vary between platforms;
1389 for example, on Windows, pressing the menu button or clicking the
1390 right mouse button will cause this event to be sent.
1392 When this event occurs it is customary to show a QMenu with a
1393 context menu, if this is relevant to the context.
1395 Context menu events contain a special accept flag that indicates
1396 whether the receiver accepted the event. If the event handler does
1397 not accept the event then, if possible, whatever triggered the event will be
1398 handled as a regular input event.
1401 #ifndef QT_NO_CONTEXTMENU
1403 Constructs a context menu event object with the accept parameter
1406 The \a reason parameter must be QContextMenuEvent::Mouse or
1407 QContextMenuEvent::Keyboard.
1409 The \a pos parameter specifies the mouse position relative to the
1410 receiving widget. \a globalPos is the mouse position in absolute
1413 QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
1414 : QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
1418 Constructs a context menu event object with the accept parameter
1421 The \a reason parameter must be QContextMenuEvent::Mouse or
1422 QContextMenuEvent::Keyboard.
1424 The \a pos parameter specifies the mouse position relative to the
1425 receiving widget. \a globalPos is the mouse position in absolute
1426 coordinates. The \a modifiers holds the keyboard modifiers.
1428 QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
1429 Qt::KeyboardModifiers modifiers)
1430 : QInputEvent(ContextMenu, modifiers), p(pos), gp(globalPos), reas(reason)
1435 QContextMenuEvent::~QContextMenuEvent()
1439 Constructs a context menu event object with the accept parameter
1442 The \a reason parameter must be QContextMenuEvent::Mouse or
1443 QContextMenuEvent::Keyboard.
1445 The \a pos parameter specifies the mouse position relative to the
1448 The globalPos() is initialized to QCursor::pos(), which may not be
1449 appropriate. Use the other constructor to specify the global
1450 position explicitly.
1452 QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
1453 : QInputEvent(ContextMenu), p(pos), reas(reason)
1455 gp = QCursor::pos();
1459 \fn const QPoint &QContextMenuEvent::pos() const
1461 Returns the position of the mouse pointer relative to the widget
1462 that received the event.
1464 \sa x(), y(), globalPos()
1468 \fn int QContextMenuEvent::x() const
1470 Returns the x position of the mouse pointer, relative to the
1471 widget that received the event.
1477 \fn int QContextMenuEvent::y() const
1479 Returns the y position of the mouse pointer, relative to the
1480 widget that received the event.
1486 \fn const QPoint &QContextMenuEvent::globalPos() const
1488 Returns the global position of the mouse pointer at the time of
1495 \fn int QContextMenuEvent::globalX() const
1497 Returns the global x position of the mouse pointer at the time of
1500 \sa globalY(), globalPos()
1504 \fn int QContextMenuEvent::globalY() const
1506 Returns the global y position of the mouse pointer at the time of
1509 \sa globalX(), globalPos()
1511 #endif // QT_NO_CONTEXTMENU
1514 \enum QContextMenuEvent::Reason
1516 This enum describes the reason why the event was sent.
1518 \value Mouse The mouse caused the event to be sent. Normally this
1519 means the right mouse button was clicked, but this is platform
1522 \value Keyboard The keyboard caused this event to be sent. On
1523 Windows, this means the menu button was pressed.
1525 \value Other The event was sent by some other means (i.e. not by
1526 the mouse or keyboard).
1531 \fn QContextMenuEvent::Reason QContextMenuEvent::reason() const
1533 Returns the reason for this context event.
1538 \class QInputMethodEvent
1539 \brief The QInputMethodEvent class provides parameters for input method events.
1544 Input method events are sent to widgets when an input method is
1545 used to enter text into a widget. Input methods are widely used
1546 to enter text for languages with non-Latin alphabets.
1548 Note that when creating custom text editing widgets, the
1549 Qt::WA_InputMethodEnabled window attribute must be set explicitly
1550 (using the QWidget::setAttribute() function) in order to receive
1551 input method events.
1553 The events are of interest to authors of keyboard entry widgets
1554 who want to be able to correctly handle languages with complex
1555 character input. Text input in such languages is usually a three
1559 \li \b{Starting to Compose}
1561 When the user presses the first key on a keyboard, an input
1562 context is created. This input context will contain a string
1563 of the typed characters.
1567 With every new key pressed, the input method will try to create a
1568 matching string for the text typed so far called preedit
1569 string. While the input context is active, the user can only move
1570 the cursor inside the string belonging to this input context.
1574 At some point, the user will activate a user interface component
1575 (perhaps using a particular key) where they can choose from a
1576 number of strings matching the text they have typed so far. The
1577 user can either confirm their choice cancel the input; in either
1578 case the input context will be closed.
1581 QInputMethodEvent models these three stages, and transfers the
1582 information needed to correctly render the intermediate result. A
1583 QInputMethodEvent has two main parameters: preeditString() and
1584 commitString(). The preeditString() parameter gives the currently
1585 active preedit string. The commitString() parameter gives a text
1586 that should get added to (or replace parts of) the text of the
1587 editor widget. It usually is a result of the input operations and
1588 has to be inserted to the widgets text directly before the preedit
1591 If the commitString() should replace parts of the of the text in
1592 the editor, replacementLength() will contain the number of
1593 characters to be replaced. replacementStart() contains the position
1594 at which characters are to be replaced relative from the start of
1597 A number of attributes control the visual appearance of the
1598 preedit string (the visual appearance of text outside the preedit
1599 string is controlled by the widget only). The AttributeType enum
1600 describes the different attributes that can be set.
1602 A class implementing QWidget::inputMethodEvent() or
1603 QGraphicsItem::inputMethodEvent() should at least understand and
1604 honor the \l TextFormat and \l Cursor attributes.
1606 Since input methods need to be able to query certain properties
1607 from the widget or graphics item, subclasses must also implement
1608 QWidget::inputMethodQuery() and QGraphicsItem::inputMethodQuery(),
1611 When receiving an input method event, the text widget has to performs the
1615 \li If the widget has selected text, the selected text should get
1618 \li Remove the text starting at replacementStart() with length
1619 replacementLength() and replace it by the commitString(). If
1620 replacementLength() is 0, replacementStart() gives the insertion
1621 position for the commitString().
1623 When doing replacement the area of the preedit
1624 string is ignored, thus a replacement starting at -1 with a length
1625 of 2 will remove the last character before the preedit string and
1626 the first character afterwards, and insert the commit string
1627 directly before the preedit string.
1629 If the widget implements undo/redo, this operation gets added to
1632 \li If there is no current preedit string, insert the
1633 preeditString() at the current cursor position; otherwise replace
1634 the previous preeditString with the one received from this event.
1636 If the widget implements undo/redo, the preeditString() should not
1637 influence the undo/redo stack in any way.
1639 The widget should examine the list of attributes to apply to the
1640 preedit string. It has to understand at least the TextFormat and
1641 Cursor attributes and render them as specified.
1648 \enum QInputMethodEvent::AttributeType
1651 A QTextCharFormat for the part of the preedit string specified by
1652 start and length. value contains a QVariant of type QTextFormat
1653 specifying rendering of this part of the preedit string. There
1654 should be at most one format for every part of the preedit
1655 string. If several are specified for any character in the string the
1656 behaviour is undefined. A conforming implementation has to at least
1657 honor the backgroundColor, textColor and fontUnderline properties
1660 \value Cursor If set, a cursor should be shown inside the preedit
1661 string at position start. The length variable determines whether
1662 the cursor is visible or not. If the length is 0 the cursor is
1663 invisible. If value is a QVariant of type QColor this color will
1664 be used for rendering the cursor, otherwise the color of the
1665 surrounding text will be used. There should be at most one Cursor
1666 attribute per event. If several are specified the behaviour is
1670 The variant contains a QLocale object specifying the language of a
1671 certain part of the preedit string. There should be at most one
1672 language set for every part of the preedit string. If several are
1673 specified for any character in the string the behavior is undefined.
1676 The ruby text for a part of the preedit string. There should be at
1677 most one ruby text set for every part of the preedit string. If
1678 several are specified for any character in the string the behaviour
1682 If set, the edit cursor should be moved to the specified position
1683 in the editor text contents. In contrast with \c Cursor, this
1684 attribute does not work on the preedit text, but on the surrounding
1685 text. The cursor will be moved after the commit string has been
1686 committed, and the preedit string will be located at the new edit
1688 The start position specifies the new position and the length
1689 variable can be used to set a selection starting from that point.
1690 The value is unused.
1696 \class QInputMethodEvent::Attribute
1697 \brief The QInputMethodEvent::Attribute class stores an input method attribute.
1701 \fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length, QVariant value)
1703 Constructs an input method attribute. \a type specifies the type
1704 of attribute, \a start and \a length the position of the
1705 attribute, and \a value the value of the attribute.
1709 Constructs an event of type QEvent::InputMethod. The
1710 attributes(), preeditString(), commitString(), replacementStart(),
1711 and replacementLength() are initialized to default values.
1713 \sa setCommitString()
1715 QInputMethodEvent::QInputMethodEvent()
1716 : QEvent(QEvent::InputMethod), replace_from(0), replace_length(0)
1721 Construcs an event of type QEvent::InputMethod. The
1722 preedit text is set to \a preeditText, the attributes to
1725 The commitString(), replacementStart(), and replacementLength()
1726 values can be set using setCommitString().
1728 \sa preeditString(), attributes()
1730 QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes)
1731 : QEvent(QEvent::InputMethod), preedit(preeditText), attrs(attributes),
1732 replace_from(0), replace_length(0)
1737 Constructs a copy of \a other.
1739 QInputMethodEvent::QInputMethodEvent(const QInputMethodEvent &other)
1740 : QEvent(QEvent::InputMethod), preedit(other.preedit), attrs(other.attrs),
1741 commit(other.commit), replace_from(other.replace_from), replace_length(other.replace_length)
1746 Sets the commit string to \a commitString.
1748 The commit string is the text that should get added to (or
1749 replace parts of) the text of the editor widget. It usually is a
1750 result of the input operations and has to be inserted to the
1751 widgets text directly before the preedit string.
1753 If the commit string should replace parts of the of the text in
1754 the editor, \a replaceLength specifies the number of
1755 characters to be replaced. \a replaceFrom specifies the position
1756 at which characters are to be replaced relative from the start of
1759 \sa commitString(), replacementStart(), replacementLength()
1761 void QInputMethodEvent::setCommitString(const QString &commitString, int replaceFrom, int replaceLength)
1763 commit = commitString;
1764 replace_from = replaceFrom;
1765 replace_length = replaceLength;
1769 \fn const QList<Attribute> &QInputMethodEvent::attributes() const
1771 Returns the list of attributes passed to the QInputMethodEvent
1772 constructor. The attributes control the visual appearance of the
1773 preedit string (the visual appearance of text outside the preedit
1774 string is controlled by the widget only).
1776 \sa preeditString(), Attribute
1780 \fn const QString &QInputMethodEvent::preeditString() const
1782 Returns the preedit text, i.e. the text before the user started
1785 \sa commitString(), attributes()
1789 \fn const QString &QInputMethodEvent::commitString() const
1791 Returns the text that should get added to (or replace parts of)
1792 the text of the editor widget. It usually is a result of the
1793 input operations and has to be inserted to the widgets text
1794 directly before the preedit string.
1796 \sa setCommitString(), preeditString(), replacementStart(), replacementLength()
1800 \fn int QInputMethodEvent::replacementStart() const
1802 Returns the position at which characters are to be replaced relative
1803 from the start of the preedit string.
1805 \sa replacementLength(), setCommitString()
1809 \fn int QInputMethodEvent::replacementLength() const
1811 Returns the number of characters to be replaced in the preedit
1814 \sa replacementStart(), setCommitString()
1818 \class QInputMethodQueryEvent
1822 \brief The QInputMethodQueryEvent class provides an event sent by the input context to input objects.
1825 input method to query a set of properties of the object to be
1826 able to support complex input method operations as support for
1827 surrounding text and reconversions.
1829 queries() specifies which properties are queried.
1831 The object should call setValue() on the event to fill in the requested
1832 data before calling accept().
1836 \fn Qt::InputMethodQueries QInputMethodQueryEvent::queries() const
1838 Returns the properties queried by the event.
1842 Constructs a query event for properties given by \a queries.
1844 QInputMethodQueryEvent::QInputMethodQueryEvent(Qt::InputMethodQueries queries)
1845 : QEvent(InputMethodQuery),
1853 QInputMethodQueryEvent::~QInputMethodQueryEvent()
1858 Sets property \a query to \a value.
1860 void QInputMethodQueryEvent::setValue(Qt::InputMethodQuery query, const QVariant &value)
1862 for (int i = 0; i < m_values.size(); ++i) {
1863 if (m_values.at(i).query == query) {
1864 m_values[i].value = value;
1868 QueryPair pair = { query, value };
1869 m_values.append(pair);
1873 Returns value of the property \a query.
1875 QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const
1877 for (int i = 0; i < m_values.size(); ++i)
1878 if (m_values.at(i).query == query)
1879 return m_values.at(i).value;
1883 #ifndef QT_NO_TABLETEVENT
1887 \brief The QTabletEvent class contains parameters that describe a Tablet event.
1892 Tablet Events are generated from a Wacom tablet. Most of the time you will
1893 want to deal with events from the tablet as if they were events from a
1894 mouse; for example, you would retrieve the cursor position with x(), y(),
1895 pos(), globalX(), globalY(), and globalPos(). In some situations you may
1896 wish to retrieve the extra information provided by the tablet device
1897 driver; for example, you might want to do subpixeling with higher
1898 resolution coordinates or you may want to adjust color brightness based on
1899 pressure. QTabletEvent allows you to read the pressure(), the xTilt(), and
1900 yTilt(), as well as the type of device being used with device() (see
1901 \l{TabletDevice}). It can also give you the minimum and maximum values for
1902 each device's pressure and high resolution coordinates.
1904 A tablet event contains a special accept flag that indicates whether the
1905 receiver wants the event. You should call QTabletEvent::accept() if you
1906 handle the tablet event; otherwise it will be sent to the parent widget.
1907 The exception are TabletEnterProximity and TabletLeaveProximity events,
1908 these are only sent to QApplication and don't check whether or not they are
1911 The QWidget::setEnabled() function can be used to enable or
1912 disable mouse and keyboard events for a widget.
1914 The event handler QWidget::tabletEvent() receives all three types of
1915 tablet events. Qt will first send a tabletEvent then, if it is not
1916 accepted, it will send a mouse event. This allows applications that
1917 don't utilize tablets to use a tablet like a mouse, while also
1918 enabling those who want to use both tablets and mouses differently.
1920 \section1 Notes for X11 Users
1922 Qt uses the following hard-coded names to identify tablet
1923 devices from the xorg.conf file on X11 (apart from IRIX):
1924 'stylus', 'pen', and 'eraser'. If the devices have other names,
1925 they will not be picked up Qt.
1929 \enum QTabletEvent::TabletDevice
1931 This enum defines what type of device is generating the event.
1933 \value NoDevice No device, or an unknown device.
1934 \value Puck A Puck (a device that is similar to a flat mouse with
1935 a transparent circle with cross-hairs).
1936 \value Stylus A Stylus.
1937 \value Airbrush An airbrush
1938 \value FourDMouse A 4D Mouse.
1939 \value RotationStylus A special stylus that also knows about rotation
1940 (a 6D stylus). \since 4.1
1941 \omitvalue XFreeEraser
1945 \enum QTabletEvent::PointerType
1947 This enum defines what type of point is generating the event.
1949 \value UnknownPointer An unknown device.
1950 \value Pen Tip end of a stylus-like device (the narrow end of the pen).
1951 \value Cursor Any puck-like device.
1952 \value Eraser Eraser end of a stylus-like device (the broad end of the pen).
1958 Construct a tablet event of the given \a type.
1960 The \a pos parameter indicates where the event occurred in the
1961 widget; \a globalPos is the corresponding position in absolute
1964 \a pressure contains the pressure exerted on the \a device.
1966 \a pointerType describes the type of pen that is being used.
1968 \a xTilt and \a yTilt contain the device's degree of tilt from the
1969 x and y axes respectively.
1971 \a keyState specifies which keyboard modifiers are pressed (e.g.,
1974 The \a uniqueID parameter contains the unique ID for the current device.
1976 The \a z parameter contains the coordinate of the device on the tablet, this
1977 is usually given by a wheel on 4D mouse. If the device does not support a
1978 Z-axis, pass zero here.
1980 The \a tangentialPressure parameter contins the tangential pressure of an air
1981 brush. If the device does not support tangential pressure, pass 0 here.
1983 \a rotation contains the device's rotation in degrees. 4D mice support
1984 rotation. If the device does not support rotation, pass 0 here.
1986 \sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt(), uniqueId(), rotation(),
1987 tangentialPressure(), z()
1990 QTabletEvent::QTabletEvent(Type type, const QPointF &pos, const QPointF &globalPos,
1991 int device, int pointerType,
1992 qreal pressure, int xTilt, int yTilt, qreal tangentialPressure,
1993 qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID)
1994 : QInputEvent(type, keyState),
1998 mPointerType(pointerType),
2003 mTangential(tangentialPressure),
2013 QTabletEvent::~QTabletEvent()
2018 \fn TabletDevices QTabletEvent::device() const
2020 Returns the type of device that generated the event.
2026 \fn PointerType QTabletEvent::pointerType() const
2028 Returns the type of point that generated the event.
2032 \fn qreal QTabletEvent::tangentialPressure() const
2034 Returns the tangential pressure for the device. This is typically given by a finger
2035 wheel on an airbrush tool. The range is from -1.0 to 1.0. 0.0 indicates a
2036 neutral position. Current airbrushes can only move in the positive
2037 direction from the neutrual position. If the device does not support
2038 tangential pressure, this value is always 0.0.
2044 \fn qreal QTabletEvent::rotation() const
2046 Returns the rotation of the current device in degress. This is usually
2047 given by a 4D Mouse. If the device doesn't support rotation this value is
2053 \fn qreal QTabletEvent::pressure() const
2055 Returns the pressure for the device. 0.0 indicates that the stylus is not
2056 on the tablet, 1.0 indicates the maximum amount of pressure for the stylus.
2058 \sa tangentialPressure()
2062 \fn int QTabletEvent::xTilt() const
2064 Returns the angle between the device (a pen, for example) and the
2065 perpendicular in the direction of the x axis.
2066 Positive values are towards the tablet's physical right. The angle
2067 is in the range -60 to +60 degrees.
2069 \image qtabletevent-tilt.png
2075 \fn int QTabletEvent::yTilt() const
2077 Returns the angle between the device (a pen, for example) and the
2078 perpendicular in the direction of the y axis.
2079 Positive values are towards the bottom of the tablet. The angle is
2080 within the range -60 to +60 degrees.
2086 \fn QPoint QTabletEvent::pos() const
2088 Returns the position of the device, relative to the widget that
2091 If you move widgets around in response to mouse events, use
2092 globalPos() instead of this function.
2094 \sa x(), y(), globalPos()
2098 \fn int QTabletEvent::x() const
2100 Returns the x position of the device, relative to the widget that
2107 \fn int QTabletEvent::y() const
2109 Returns the y position of the device, relative to the widget that
2116 \fn int QTabletEvent::z() const
2118 Returns the z position of the device. Typically this is represented by a
2119 wheel on a 4D Mouse. If the device does not support a Z-axis, this value is
2120 always zero. This is \b not the same as pressure.
2126 \fn QPoint QTabletEvent::globalPos() const
2128 Returns the global position of the device \e{at the time of the
2129 event}. This is important on asynchronous windows systems like X11;
2130 whenever you move your widgets around in response to mouse events,
2131 globalPos() can differ significantly from the current position
2134 \sa globalX(), globalY(), hiResGlobalPos()
2138 \fn int QTabletEvent::globalX() const
2140 Returns the global x position of the mouse pointer at the time of
2143 \sa globalY(), globalPos(), hiResGlobalX()
2147 \fn int QTabletEvent::globalY() const
2149 Returns the global y position of the tablet device at the time of
2152 \sa globalX(), globalPos(), hiResGlobalY()
2156 \fn qint64 QTabletEvent::uniqueId() const
2158 Returns a unique ID for the current device, making it possible
2159 to differentiate between multiple devices being used at the same
2162 Support of this feature is dependent on the tablet.
2164 Values for the same device may vary from OS to OS.
2166 Later versions of the Wacom driver for Linux will now report
2167 the ID information. If you have a tablet that supports unique ID
2168 and are not getting the information on Linux, consider upgrading
2171 As of Qt 4.2, the unique ID is the same regardless of the orientation
2172 of the pen. Earlier versions would report a different value when using
2173 the eraser-end versus the pen-end of the stylus on some OS's.
2179 \fn const QPointF &QTabletEvent::hiResGlobalPos() const
2181 The high precision coordinates delivered from the tablet expressed.
2182 Sub pixeling information is in the fractional part of the QPointF.
2184 \sa globalPos(), hiResGlobalX(), hiResGlobalY()
2188 \fn qreal &QTabletEvent::hiResGlobalX() const
2190 The high precision x position of the tablet device.
2194 \fn qreal &QTabletEvent::hiResGlobalY() const
2196 The high precision y position of the tablet device.
2200 \fn const QPointF &QTabletEvent::posF() const
2202 Returns the position of the device, relative to the widget that
2205 If you move widgets around in response to mouse events, use
2206 globalPosF() instead of this function.
2212 \fn const QPointF &QTabletEvent::globalPosF() const
2214 Returns the global position of the device \e{at the time of the
2215 event}. This is important on asynchronous windows systems like X11;
2216 whenever you move your widgets around in response to mouse events,
2217 globalPosF() can differ significantly from the current position
2223 #endif // QT_NO_TABLETEVENT
2225 #ifndef QT_NO_DRAGANDDROP
2227 Creates a QDragMoveEvent of the required \a type indicating
2228 that the mouse is at position \a pos given within a widget.
2230 The mouse and keyboard states are specified by \a buttons and
2231 \a modifiers, and the \a actions describe the types of drag
2232 and drop operation that are possible.
2233 The drag data is passed as MIME-encoded information in \a data.
2235 \warning Do not attempt to create a QDragMoveEvent yourself.
2236 These objects rely on Qt's internal state.
2238 QDragMoveEvent::QDragMoveEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
2239 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
2240 : QDropEvent(pos, actions, data, buttons, modifiers, type)
2241 , rect(pos, QSize(1, 1))
2247 QDragMoveEvent::~QDragMoveEvent()
2252 \fn void QDragMoveEvent::accept(const QRect &rectangle)
2254 The same as accept(), but also notifies that future moves will
2255 also be acceptable if they remain within the \a rectangle
2256 given on the widget. This can improve performance, but may
2257 also be ignored by the underlying system.
2259 If the rectangle is empty, drag move events will be sent
2260 continuously. This is useful if the source is scrolling in a
2265 \fn void QDragMoveEvent::accept()
2269 Calls QDropEvent::accept().
2273 \fn void QDragMoveEvent::ignore()
2277 Calls QDropEvent::ignore().
2281 \fn void QDragMoveEvent::ignore(const QRect &rectangle)
2283 The opposite of the accept(const QRect&) function.
2284 Moves within the \a rectangle are not acceptable, and will be
2289 \fn QRect QDragMoveEvent::answerRect() const
2291 Returns the rectangle in the widget where the drop will occur if accepted.
2292 You can use this information to restrict drops to certain places on the
2300 \ingroup draganddrop
2303 \brief The QDropEvent class provides an event which is sent when a
2304 drag and drop action is completed.
2306 When a widget \l{QWidget::setAcceptDrops()}{accepts drop events}, it will
2307 receive this event if it has accepted the most recent QDragEnterEvent or
2308 QDragMoveEvent sent to it.
2310 The drop event contains a proposed action, available from proposedAction(), for
2311 the widget to either accept or ignore. If the action can be handled by the
2312 widget, you should call the acceptProposedAction() function. Since the
2313 proposed action can be a combination of \l Qt::DropAction values, it may be
2314 useful to either select one of these values as a default action or ask
2315 the user to select their preferred action.
2317 If the proposed drop action is not suitable, perhaps because your custom
2318 widget does not support that action, you can replace it with any of the
2319 \l{possibleActions()}{possible drop actions} by calling setDropAction()
2320 with your preferred action. If you set a value that is not present in the
2321 bitwise OR combination of values returned by possibleActions(), the default
2322 copy action will be used. Once a replacement drop action has been set, call
2323 accept() instead of acceptProposedAction() to complete the drop operation.
2325 The mimeData() function provides the data dropped on the widget in a QMimeData
2326 object. This contains information about the MIME type of the data in addition to
2329 \sa QMimeData, QDrag, {Drag and Drop}
2333 \fn const QMimeData *QDropEvent::mimeData() const
2335 Returns the data that was dropped on the widget and its associated MIME
2340 Constructs a drop event of a certain \a type corresponding to a
2341 drop at the point specified by \a pos in the destination widget's
2344 The \a actions indicate which types of drag and drop operation can
2345 be performed, and the drag data is stored as MIME-encoded data in \a data.
2347 The states of the mouse buttons and keyboard modifiers at the time of
2348 the drop are specified by \a buttons and \a modifiers.
2349 */ // ### pos is in which coordinate system?
2350 QDropEvent::QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
2351 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
2352 : QEvent(type), p(pos), mouseState(buttons),
2353 modState(modifiers), act(actions),
2356 default_action = QGuiApplicationPrivate::platformIntegration()->drag()->defaultAction(act, modifiers);
2357 drop_action = default_action;
2362 QDropEvent::~QDropEvent()
2368 If the source of the drag operation is a widget in this
2369 application, this function returns that source; otherwise it
2370 returns 0. The source of the operation is the first parameter to
2371 the QDrag object used instantiate the drag.
2373 This is useful if your widget needs special behavior when dragging
2378 QObject* QDropEvent::source() const
2380 if (const QDragManager *manager = QDragManager::self())
2381 return manager->source();
2386 void QDropEvent::setDropAction(Qt::DropAction action)
2388 if (!(action & act) && action != Qt::IgnoreAction)
2389 action = default_action;
2390 drop_action = action;
2394 \fn QPoint QDropEvent::pos() const
2396 Returns the position where the drop was made.
2400 \fn const QPointF& QDropEvent::posF() const
2402 Returns the position where the drop was made.
2406 \fn Qt::MouseButtons QDropEvent::mouseButtons() const
2408 Returns the mouse buttons that are pressed..
2412 \fn Qt::KeyboardModifiers QDropEvent::keyboardModifiers() const
2414 Returns the modifier keys that are pressed.
2418 \fn void QDropEvent::setDropAction(Qt::DropAction action)
2420 Sets the \a action to be performed on the data by the target.
2421 Use this to override the \l{proposedAction()}{proposed action}
2422 with one of the \l{possibleActions()}{possible actions}.
2424 If you set a drop action that is not one of the possible actions, the
2425 drag and drop operation will default to a copy operation.
2427 Once you have supplied a replacement drop action, call accept()
2428 instead of acceptProposedAction().
2434 \fn Qt::DropAction QDropEvent::dropAction() const
2436 Returns the action to be performed on the data by the target. This may be
2437 different from the action supplied in proposedAction() if you have called
2438 setDropAction() to explicitly choose a drop action.
2444 \fn Qt::DropActions QDropEvent::possibleActions() const
2446 Returns an OR-combination of possible drop actions.
2452 \fn Qt::DropAction QDropEvent::proposedAction() const
2454 Returns the proposed drop action.
2460 \fn void QDropEvent::acceptProposedAction()
2462 Sets the drop action to be the proposed action.
2464 \sa setDropAction(), proposedAction(), {QEvent::accept()}{accept()}
2468 \class QDragEnterEvent
2469 \brief The QDragEnterEvent class provides an event which is sent
2470 to a widget when a drag and drop action enters it.
2473 \ingroup draganddrop
2476 A widget must accept this event in order to receive the \l
2477 {QDragMoveEvent}{drag move events} that are sent while the drag
2478 and drop action is in progress. The drag enter event is always
2479 immediately followed by a drag move event.
2481 QDragEnterEvent inherits most of its functionality from
2482 QDragMoveEvent, which in turn inherits most of its functionality
2485 \sa QDragLeaveEvent, QDragMoveEvent, QDropEvent
2489 Constructs a QDragEnterEvent that represents a drag entering a
2490 widget at the given \a point with mouse and keyboard states specified by
2491 \a buttons and \a modifiers.
2493 The drag data is passed as MIME-encoded information in \a data, and the
2494 specified \a actions describe the possible types of drag and drop
2495 operation that can be performed.
2497 \warning Do not create a QDragEnterEvent yourself since these
2498 objects rely on Qt's internal state.
2500 QDragEnterEvent::QDragEnterEvent(const QPoint& point, Qt::DropActions actions, const QMimeData *data,
2501 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
2502 : QDragMoveEvent(point, actions, data, buttons, modifiers, DragEnter)
2507 QDragEnterEvent::~QDragEnterEvent()
2512 \class QDragMoveEvent
2513 \brief The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress.
2516 \ingroup draganddrop
2519 A widget will receive drag move events repeatedly while the drag
2520 is within its boundaries, if it accepts
2521 \l{QWidget::setAcceptDrops()}{drop events} and \l
2522 {QWidget::dragEnterEvent()}{enter events}. The widget should
2523 examine the event to see what kind of data it
2524 \l{QDragMoveEvent::provides()}{provides}, and call the accept()
2525 function to accept the drop if appropriate.
2527 The rectangle supplied by the answerRect() function can be used to restrict
2528 drops to certain parts of the widget. For example, we can check whether the
2529 rectangle intersects with the geometry of a certain child widget and only
2530 call \l{QDropEvent::acceptProposedAction()}{acceptProposedAction()} if that
2533 Note that this class inherits most of its functionality from
2536 \sa QDragEnterEvent, QDragLeaveEvent, QDropEvent
2540 \class QDragLeaveEvent
2541 \brief The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leaves it.
2544 \ingroup draganddrop
2547 This event is always preceded by a QDragEnterEvent and a series
2548 of \l{QDragMoveEvent}s. It is not sent if a QDropEvent is sent
2551 \sa QDragEnterEvent, QDragMoveEvent, QDropEvent
2555 Constructs a QDragLeaveEvent.
2557 \warning Do not create a QDragLeaveEvent yourself since these
2558 objects rely on Qt's internal state.
2560 QDragLeaveEvent::QDragLeaveEvent()
2566 QDragLeaveEvent::~QDragLeaveEvent()
2569 #endif // QT_NO_DRAGANDDROP
2573 \brief The QHelpEvent class provides an event that is used to request helpful information
2574 about a particular point in a widget.
2580 This event can be intercepted in applications to provide tooltips
2581 or "What's This?" help for custom widgets. The type() can be
2582 either QEvent::ToolTip or QEvent::WhatsThis.
2584 \sa QToolTip, QWhatsThis, QStatusTipEvent, QWhatsThisClickedEvent
2588 Constructs a help event with the given \a type corresponding to the
2589 widget-relative position specified by \a pos and the global position
2590 specified by \a globalPos.
2592 \a type must be either QEvent::ToolTip or QEvent::WhatsThis.
2594 \sa pos(), globalPos()
2596 QHelpEvent::QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos)
2597 : QEvent(type), p(pos), gp(globalPos)
2601 \fn int QHelpEvent::x() const
2605 \sa y(), pos(), globalPos()
2609 \fn int QHelpEvent::y() const
2613 \sa x(), pos(), globalPos()
2617 \fn int QHelpEvent::globalX() const
2619 Same as globalPos().x().
2621 \sa x(), globalY(), globalPos()
2625 \fn int QHelpEvent::globalY() const
2627 Same as globalPos().y().
2629 \sa y(), globalX(), globalPos()
2633 \fn const QPoint &QHelpEvent::pos() const
2635 Returns the mouse cursor position when the event was generated,
2636 relative to the widget to which the event is dispatched.
2638 \sa globalPos(), x(), y()
2642 \fn const QPoint &QHelpEvent::globalPos() const
2644 Returns the mouse cursor position when the event was generated
2645 in global coordinates.
2647 \sa pos(), globalX(), globalY()
2652 QHelpEvent::~QHelpEvent()
2656 #ifndef QT_NO_STATUSTIP
2659 \class QStatusTipEvent
2660 \brief The QStatusTipEvent class provides an event that is used to show messages in a status bar.
2666 Status tips can be set on a widget using the
2667 QWidget::setStatusTip() function. They are shown in the status
2668 bar when the mouse cursor enters the widget. For example:
2673 \snippet qstatustipevent/main.cpp 1
2675 \snippet qstatustipevent/main.cpp 3
2677 \image qstatustipevent-widget.png Widget with status tip.
2680 Status tips can also be set on actions using the
2681 QAction::setStatusTip() function:
2686 \snippet qstatustipevent/main.cpp 0
2687 \snippet qstatustipevent/main.cpp 2
2689 \snippet qstatustipevent/main.cpp 3
2691 \image qstatustipevent-action.png Action with status tip.
2694 Finally, status tips are supported for the item view classes
2695 through the Qt::StatusTipRole enum value.
2697 \sa QStatusBar, QHelpEvent, QWhatsThisClickedEvent
2701 Constructs a status tip event with the text specified by \a tip.
2705 QStatusTipEvent::QStatusTipEvent(const QString &tip)
2706 : QEvent(StatusTip), s(tip)
2711 QStatusTipEvent::~QStatusTipEvent()
2716 \fn QString QStatusTipEvent::tip() const
2718 Returns the message to show in the status bar.
2720 \sa QStatusBar::showMessage()
2723 #endif // QT_NO_STATUSTIP
2725 #ifndef QT_NO_WHATSTHIS
2728 \class QWhatsThisClickedEvent
2729 \brief The QWhatsThisClickedEvent class provides an event that
2730 can be used to handle hyperlinks in a "What's This?" text.
2736 \sa QWhatsThis, QHelpEvent, QStatusTipEvent
2740 Constructs an event containing a URL specified by \a href when a link
2741 is clicked in a "What's This?" message.
2745 QWhatsThisClickedEvent::QWhatsThisClickedEvent(const QString &href)
2746 : QEvent(WhatsThisClicked), s(href)
2751 QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
2756 \fn QString QWhatsThisClickedEvent::href() const
2758 Returns the URL that was clicked by the user in the "What's
2762 #endif // QT_NO_WHATSTHIS
2764 #ifndef QT_NO_ACTION
2768 \brief The QActionEvent class provides an event that is generated
2769 when a QAction is added, removed, or changed.
2774 Actions can be added to widgets using QWidget::addAction(). This
2775 generates an \l ActionAdded event, which you can handle to provide
2776 custom behavior. For example, QToolBar reimplements
2777 QWidget::actionEvent() to create \l{QToolButton}s for the
2780 \sa QAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions()
2784 Constructs an action event. The \a type can be \l ActionChanged,
2785 \l ActionAdded, or \l ActionRemoved.
2787 \a action is the action that is changed, added, or removed. If \a
2788 type is ActionAdded, the action is to be inserted before the
2789 action \a before. If \a before is 0, the action is appended.
2791 QActionEvent::QActionEvent(int type, QAction *action, QAction *before)
2792 : QEvent(static_cast<QEvent::Type>(type)), act(action), bef(before)
2797 QActionEvent::~QActionEvent()
2802 \fn QAction *QActionEvent::action() const
2804 Returns the action that is changed, added, or removed.
2810 \fn QAction *QActionEvent::before() const
2812 If type() is \l ActionAdded, returns the action that should
2813 appear before action(). If this function returns 0, the action
2814 should be appended to already existing actions on the same
2817 \sa action(), QWidget::actions()
2820 #endif // QT_NO_ACTION
2824 \brief The QHideEvent class provides an event which is sent after a widget is hidden.
2829 This event is sent just before QWidget::hide() returns, and also
2830 when a top-level window has been hidden (iconified) by the user.
2832 If spontaneous() is true, the event originated outside the
2833 application. In this case, the user hid the window using the
2834 window manager controls, either by iconifying the window or by
2835 switching to another virtual desktop where the window isn't
2836 visible. The window will become hidden but not withdrawn. If the
2837 window was iconified, QWidget::isMinimized() returns true.
2843 Constructs a QHideEvent.
2845 QHideEvent::QHideEvent()
2851 QHideEvent::~QHideEvent()
2857 \brief The QShowEvent class provides an event that is sent when a widget is shown.
2862 There are two kinds of show events: show events caused by the
2863 window system (spontaneous), and internal show events. Spontaneous (QEvent::spontaneous())
2864 show events are sent just after the window system shows the
2865 window; they are also sent when a top-level window is redisplayed
2866 after being iconified. Internal show events are delivered just
2867 before the widget becomes visible.
2873 Constructs a QShowEvent.
2875 QShowEvent::QShowEvent()
2881 QShowEvent::~QShowEvent()
2886 \class QFileOpenEvent
2887 \brief The QFileOpenEvent class provides an event that will be
2888 sent when there is a request to open a file or a URL.
2893 File open events will be sent to the QApplication::instance()
2894 when the operating system requests that a file or URL should be opened.
2895 This is a high-level event that can be caused by different user actions
2896 depending on the user's desktop environment; for example, double
2897 clicking on an file icon in the Finder on Mac OS X.
2899 This event is only used to notify the application of a request.
2900 It may be safely ignored.
2902 \note This class is currently supported for Mac OS X only.
2908 Constructs a file open event for the given \a file.
2910 QFileOpenEvent::QFileOpenEvent(const QString &file)
2911 : QEvent(FileOpen), f(file), m_url(QUrl::fromLocalFile(file))
2918 Constructs a file open event for the given \a url.
2920 QFileOpenEvent::QFileOpenEvent(const QUrl &url)
2921 : QEvent(FileOpen), f(url.toLocalFile()), m_url(url)
2928 QFileOpenEvent::~QFileOpenEvent()
2933 \fn QString QFileOpenEvent::file() const
2935 Returns the file that is being opened.
2939 \fn QUrl QFileOpenEvent::url() const
2941 Returns the url that is being opened.
2947 \fn bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
2949 Opens a QFile on the \a file referenced by this event in the mode specified
2950 by \a flags. Returns true if successful; otherwise returns false.
2952 This is necessary as some files cannot be opened by name, but require specific
2953 information stored in this event.
2957 bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
2959 file.setFileName(f);
2960 return file.open(flags);
2963 #ifndef QT_NO_TOOLBAR
2966 \class QToolBarChangeEvent
2967 \brief The QToolBarChangeEvent class provides an event that is
2968 sent whenever a the toolbar button is clicked on Mac OS X.
2973 The QToolBarChangeEvent is sent when the toolbar button is clicked. On Mac
2974 OS X, this is the long oblong button on the right side of the window
2975 title bar. The default implementation is to toggle the appearance (hidden or
2976 shown) of the associated toolbars for the window.
2982 Construct a QToolBarChangeEvent given the current button state in \a state.
2984 QToolBarChangeEvent::QToolBarChangeEvent(bool t)
2985 : QEvent(ToolBarChange), tog(t)
2990 QToolBarChangeEvent::~QToolBarChangeEvent()
2995 \fn bool QToolBarChangeEvent::toggle() const
3000 \fn Qt::ButtonState QToolBarChangeEvent::state() const
3002 Returns the keyboard modifier flags at the time of the event.
3004 The returned value is a selection of the following values,
3005 combined using the OR operator:
3006 Qt::ShiftButton, Qt::ControlButton, Qt::MetaButton, and Qt::AltButton.
3009 #endif // QT_NO_TOOLBAR
3011 #ifndef QT_NO_SHORTCUT
3014 Constructs a shortcut event for the given \a key press,
3015 associated with the QShortcut ID \a id.
3017 \a ambiguous specifies whether there is more than one QShortcut
3018 for the same key sequence.
3020 QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous)
3021 : QEvent(Shortcut), sequence(key), ambig(ambiguous), sid(id)
3026 Destroys the event object.
3028 QShortcutEvent::~QShortcutEvent()
3032 #endif // QT_NO_SHORTCUT
3034 #ifndef QT_NO_DEBUG_STREAM
3035 QDebug operator<<(QDebug dbg, const QEvent *e) {
3036 // More useful event output could be added here
3038 return dbg << "QEvent(this = 0x0)";
3040 switch (e->type()) {
3044 case QEvent::MouseButtonPress:
3045 case QEvent::MouseMove:
3046 case QEvent::MouseButtonRelease:
3047 case QEvent::MouseButtonDblClick:
3049 const QMouseEvent *me = static_cast<const QMouseEvent*>(e);
3050 switch(me->type()) {
3051 case QEvent::MouseButtonPress:
3052 n = "MouseButtonPress";
3054 case QEvent::MouseMove:
3057 case QEvent::MouseButtonRelease:
3058 n = "MouseButtonRelease";
3060 case QEvent::MouseButtonDblClick:
3062 n = "MouseButtonDblClick";
3065 dbg.nospace() << "QMouseEvent(" << n
3066 << ", " << me->button()
3067 << ", " << hex << (int)me->buttons()
3068 << ", " << hex << (int)me->modifiers()
3073 #ifndef QT_NO_TOOLTIP
3074 case QEvent::ToolTip:
3078 case QEvent::WindowActivate:
3079 n = "WindowActivate";
3081 case QEvent::WindowDeactivate:
3082 n = "WindowDeactivate";
3084 case QEvent::ActivationChange:
3085 n = "ActivationChange";
3087 #ifndef QT_NO_WHEELEVENT
3089 dbg.nospace() << "QWheelEvent("
3090 << static_cast<const QWheelEvent *>(e)->pixelDelta()
3091 << static_cast<const QWheelEvent *>(e)->angleDelta()
3095 case QEvent::KeyPress:
3096 case QEvent::KeyRelease:
3097 case QEvent::ShortcutOverride:
3099 const QKeyEvent *ke = static_cast<const QKeyEvent*>(e);
3100 switch(ke->type()) {
3101 case QEvent::ShortcutOverride:
3102 n = "ShortcutOverride";
3104 case QEvent::KeyRelease:
3107 case QEvent::KeyPress:
3112 dbg.nospace() << "QKeyEvent(" << n
3113 << ", " << hex << ke->key()
3114 << ", " << hex << (int)ke->modifiers()
3115 << ", \"" << ke->text()
3116 << "\", " << ke->isAutoRepeat()
3117 << ", " << ke->count()
3121 case QEvent::FocusIn:
3124 case QEvent::FocusOut:
3133 case QEvent::PaletteChange:
3134 n = "PaletteChange";
3136 case QEvent::PolishRequest:
3137 n = "PolishRequest";
3139 case QEvent::Polish:
3142 case QEvent::UpdateRequest:
3143 n = "UpdateRequest";
3151 case QEvent::Resize:
3154 case QEvent::Create:
3157 case QEvent::Destroy:
3166 case QEvent::FileOpen:
3172 case QEvent::ShowToParent:
3178 case QEvent::HideToParent:
3184 case QEvent::ParentChange:
3187 case QEvent::ParentAboutToChange:
3188 n = "ParentAboutToChange";
3190 case QEvent::HoverEnter:
3193 case QEvent::HoverMove:
3196 case QEvent::HoverLeave:
3199 case QEvent::ZOrderChange:
3202 case QEvent::StyleChange:
3205 case QEvent::DragEnter:
3208 case QEvent::DragMove:
3211 case QEvent::DragLeave:
3217 case QEvent::GraphicsSceneMouseMove:
3218 n = "GraphicsSceneMouseMove";
3220 case QEvent::GraphicsSceneMousePress:
3221 n = "GraphicsSceneMousePress";
3223 case QEvent::GraphicsSceneMouseRelease:
3224 n = "GraphicsSceneMouseRelease";
3226 case QEvent::GraphicsSceneMouseDoubleClick:
3227 n = "GraphicsSceneMouseDoubleClick";
3229 case QEvent::GraphicsSceneContextMenu:
3230 n = "GraphicsSceneContextMenu";
3232 case QEvent::GraphicsSceneHoverEnter:
3233 n = "GraphicsSceneHoverEnter";
3235 case QEvent::GraphicsSceneHoverMove:
3236 n = "GraphicsSceneHoverMove";
3238 case QEvent::GraphicsSceneHoverLeave:
3239 n = "GraphicsSceneHoverLeave";
3241 case QEvent::GraphicsSceneHelp:
3242 n = "GraphicsSceneHelp";
3244 case QEvent::GraphicsSceneDragEnter:
3245 n = "GraphicsSceneDragEnter";
3247 case QEvent::GraphicsSceneDragMove:
3248 n = "GraphicsSceneDragMove";
3250 case QEvent::GraphicsSceneDragLeave:
3251 n = "GraphicsSceneDragLeave";
3253 case QEvent::GraphicsSceneDrop:
3254 n = "GraphicsSceneDrop";
3256 case QEvent::GraphicsSceneWheel:
3257 n = "GraphicsSceneWheel";
3259 case QEvent::GraphicsSceneResize:
3260 n = "GraphicsSceneResize";
3262 case QEvent::GraphicsSceneMove:
3263 n = "GraphicsSceneMove";
3265 case QEvent::CursorChange:
3268 case QEvent::ToolTipChange:
3269 n = "ToolTipChange";
3271 case QEvent::StatusTip:
3274 case QEvent::WhatsThis:
3277 case QEvent::FontChange:
3283 case QEvent::KeyboardLayoutChange:
3284 n = "KeyboardLayoutChange";
3286 case QEvent::DynamicPropertyChange:
3287 n = "DynamicPropertyChange";
3289 case QEvent::GrabMouse:
3292 case QEvent::UngrabMouse:
3295 case QEvent::GrabKeyboard:
3298 case QEvent::UngrabKeyboard:
3299 n = "UngrabKeyboard";
3301 case QEvent::ChildAdded: n = n ? n : "ChildAdded";
3302 case QEvent::ChildPolished: n = n ? n : "ChildPolished";
3303 case QEvent::ChildRemoved: n = n ? n : "ChildRemoved";
3304 dbg.nospace() << "QChildEvent(" << n << ", " << (static_cast<const QChildEvent*>(e))->child();
3306 #ifndef QT_NO_GESTURES
3307 case QEvent::Gesture:
3312 dbg.nospace() << "QEvent(" << (const void *)e << ", type = " << e->type() << ')';
3316 dbg.nospace() << 'Q' << n << "Event(" << (const void *)e << ')';
3322 \class QShortcutEvent
3323 \brief The QShortcutEvent class provides an event which is generated when
3324 the user presses a key combination.
3329 Normally you don't need to use this class directly; QShortcut
3330 provides a higher-level interface to handle shortcut keys.
3336 \fn const QKeySequence &QShortcutEvent::key() const
3338 Returns the key sequence that triggered the event.
3342 \fn int QShortcutEvent::shortcutId() const
3344 Returns the ID of the QShortcut object for which this event was
3351 \fn bool QShortcutEvent::isAmbiguous() const
3353 Returns true if the key sequence that triggered the event is
3356 \sa QShortcut::activatedAmbiguously()
3360 \class QWindowStateChangeEvent
3364 \brief The QWindowStateChangeEvent class provides the window state before a
3365 window state change.
3368 /*! \fn Qt::WindowStates QWindowStateChangeEvent::oldState() const
3370 Returns the state of the window before the change.
3375 QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s, bool isOverride)
3376 : QEvent(WindowStateChange), ostate(s), m_override(isOverride)
3382 bool QWindowStateChangeEvent::isOverride() const
3389 QWindowStateChangeEvent::~QWindowStateChangeEvent()
3396 \brief The QTouchEvent class contains parameters that describe a touch event.
3402 \section1 Enabling Touch Events
3404 Touch events occur when pressing, releasing, or moving one or more touch points on a touch
3405 device (such as a touch-screen or track-pad). To receive touch events, widgets have to have the
3406 Qt::WA_AcceptTouchEvents attribute set and graphics items need to have the
3407 \l{QGraphicsItem::setAcceptTouchEvents()}{acceptTouchEvents} attribute set to true.
3409 When using QAbstractScrollArea based widgets, you should enable the Qt::WA_AcceptTouchEvents
3410 attribute on the scroll area's \l{QAbstractScrollArea::viewport()}{viewport}.
3412 Similarly to QMouseEvent, Qt automatically grabs each touch point on the first press inside a
3413 widget, and the widget will receive all updates for the touch point until it is released.
3414 Note that it is possible for a widget to receive events for numerous touch points, and that
3415 multiple widgets may be receiving touch events at the same time.
3417 \section1 Event Handling
3419 All touch events are of type QEvent::TouchBegin, QEvent::TouchUpdate, QEvent::TouchEnd or
3420 QEvent::TouchCancel. Reimplement QWidget::event() or QAbstractScrollArea::viewportEvent() for
3421 widgets and QGraphicsItem::sceneEvent() for items in a graphics view to receive touch events.
3423 Unlike widgets, QWindows receive touch events always, there is no need to opt in. When working
3424 directly with a QWindow, it is enough to reimplement QWindow::touchEvent().
3426 The QEvent::TouchUpdate and QEvent::TouchEnd events are sent to the widget or item that
3427 accepted the QEvent::TouchBegin event. If the QEvent::TouchBegin event is not accepted and not
3428 filtered by an event filter, then no further touch events are sent until the next
3431 Some systems may send an event of type QEvent::TouchCancel. Upon receiving this event
3432 applications are requested to ignore the entire active touch sequence. For example in a
3433 composited system the compositor may decide to treat certain gestures as system-wide
3434 gestures. Whenever such a decision is made (the gesture is recognized), the clients will be
3435 notified with a QEvent::TouchCancel event so they can update their state accordingly.
3437 The touchPoints() function returns a list of all touch points contained in the event. Note that
3438 this list may be empty, for example in case of a QEvent::TouchCancel event. Information about
3439 each touch point can be retrieved using the QTouchEvent::TouchPoint class. The
3440 Qt::TouchPointState enum describes the different states that a touch point may have.
3442 \note The list of touchPoints() will never be partial: A touch event will always contain a touch
3443 point for each existing physical touch contacts targetting the window or widget to which the
3444 event is sent. For instance, assuming that all touches target the same window or widget, an
3445 event with a condition of touchPoints().count()==2 is guaranteed to imply that the number of
3446 fingers touching the touchscreen or touchpad is exactly two.
3448 \section1 Event Delivery and Propagation
3450 By default, QGuiApplication translates the first touch point in a QTouchEvent into
3451 a QMouseEvent. This makes it possible to enable touch events on existing widgets that do not
3452 normally handle QTouchEvent. See below for information on some special considerations needed
3455 QEvent::TouchBegin is the first touch event sent to a widget. The QEvent::TouchBegin event
3456 contains a special accept flag that indicates whether the receiver wants the event. By default,
3457 the event is accepted. You should call ignore() if the touch event is not handled by your
3458 widget. The QEvent::TouchBegin event is propagated up the parent widget chain until a widget
3459 accepts it with accept(), or an event filter consumes it. For QGraphicsItems, the
3460 QEvent::TouchBegin event is propagated to items under the mouse (similar to mouse event
3461 propagation for QGraphicsItems).
3463 \section1 Touch Point Grouping
3465 As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the
3466 same time. However, Qt makes sure to never send duplicate QEvent::TouchBegin events to the same
3467 widget, which could theoretically happen during propagation if, for example, the user touched 2
3468 separate widgets in a QGroupBox and both widgets ignored the QEvent::TouchBegin event.
3470 To avoid this, Qt will group new touch points together using the following rules:
3474 \li When the first touch point is detected, the destination widget is determined firstly by the
3475 location on screen and secondly by the propagation rules.
3477 \li When additional touch points are detected, Qt first looks to see if there are any active
3478 touch points on any ancestor or descendent of the widget under the new touch point. If there
3479 are, the new touch point is grouped with the first, and the new touch point will be sent in a
3480 single QTouchEvent to the widget that handled the first touch point. (The widget under the new
3481 touch point will not receive an event).
3485 This makes it possible for sibling widgets to handle touch events independently while making
3486 sure that the sequence of QTouchEvents is always correct.
3488 \section1 Mouse Events and Touch Event synthesizing
3490 QTouchEvent delivery is independent from that of QMouseEvent. The application flags
3491 Qt::AA_SynthesizeTouchForUnhandledMouseEvents and Qt::AA_SynthesizeMouseForUnhandledTouchEvents
3492 can be used to enable or disable automatic synthesizing of touch events to mouse events and
3493 mouse events to touch events.
3499 \li As mentioned above, enabling touch events means multiple widgets can be receiving touch
3500 events simultaneously. Combined with the default QWidget::event() handling for QTouchEvents,
3501 this gives you great flexibility in designing touch user interfaces. Be aware of the
3502 implications. For example, it is possible that the user is moving a QSlider with one finger and
3503 pressing a QPushButton with another. The signals emitted by these widgets will be
3506 \li Recursion into the event loop using one of the exec() methods (e.g., QDialog::exec() or
3507 QMenu::exec()) in a QTouchEvent event handler is not supported. Since there are multiple event
3508 recipients, recursion may cause problems, including but not limited to lost events
3509 and unexpected infinite recursion.
3511 \li QTouchEvents are not affected by a \l{QWidget::grabMouse()}{mouse grab} or an
3512 \l{QApplication::activePopupWidget()}{active pop-up widget}. The behavior of QTouchEvents is
3513 undefined when opening a pop-up or grabbing the mouse while there are more than one active touch
3518 \sa QTouchEvent::TouchPoint, Qt::TouchPointState, Qt::WA_AcceptTouchEvents,
3519 QGraphicsItem::acceptTouchEvents()
3522 /*! \enum QTouchEvent::DeviceType
3525 This enum represents the type of device that generated a QTouchEvent.
3527 This enum has been deprecated. Use QTouchDevice::DeviceType instead.
3529 \omitvalue TouchScreen
3531 \sa QTouchDevice::DeviceType, QTouchDevice::type(), QTouchEvent::device()
3535 Constructs a QTouchEvent with the given \a eventType, \a device, and
3536 \a touchPoints. The \a touchPointStates and \a modifiers
3537 are the current touch point states and keyboard modifiers at the time of
3540 QTouchEvent::QTouchEvent(QEvent::Type eventType,
3541 QTouchDevice *device,
3542 Qt::KeyboardModifiers modifiers,
3543 Qt::TouchPointStates touchPointStates,
3544 const QList<QTouchEvent::TouchPoint> &touchPoints)
3545 : QInputEvent(eventType, modifiers),
3549 _touchPointStates(touchPointStates),
3550 _touchPoints(touchPoints)
3554 Destroys the QTouchEvent.
3556 QTouchEvent::~QTouchEvent()
3559 /*! \fn QWindow *QTouchEvent::window() const
3561 Returns the window on which the event occurred. Useful for doing
3562 global-local mapping on data like rawScreenPositions() which,
3563 for performance reasons, only stores the global positions in the
3567 /*! \fn QObject *QTouchEvent::target() const
3569 Returns the target object within the window on which the event occurred.
3570 This is typically a QWidget or a QQuickItem. May be 0 when no specific target is available.
3573 /*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const
3576 Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}.
3578 This function has been deprecated. Use QTouchDevice::type() instead.
3580 \sa QTouchDevice::type(), QTouchEvent::device()
3583 /*! \fn Qt::TouchPointStates QTouchEvent::touchPointStates() const
3585 Returns a bitwise OR of all the touch point states for this event.
3588 /*! \fn const QList<QTouchEvent::TouchPoint> &QTouchEvent::touchPoints() const
3590 Returns the list of touch points contained in the touch event.
3593 /*! \fn QTouchDevice* QTouchEvent::device() const
3595 Returns the touch device from which this touch event originates.
3598 /*! \fn void QTouchEvent::setWindow(QWindow *window)
3602 Sets the window for this event.
3605 /*! \fn void QTouchEvent::setTarget(QObject *target)
3609 Sets the target within the window (typically a widget) for this event.
3612 /*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates)
3616 Sets a bitwise OR of all the touch point states for this event.
3619 /*! \fn void QTouchEvent::setTouchPoints(const QList<QTouchEvent::TouchPoint> &touchPoints)
3623 Sets the list of touch points for this event.
3626 /*! \fn void QTouchEvent::setDevice(QTouchDevice *adevice)
3630 Sets the device to \a adevice.
3633 /*! \class QTouchEvent::TouchPoint
3634 \brief The TouchPoint class provides information about a touch point in a QTouchEvent.
3639 /*! \enum TouchPoint::InfoFlag
3641 The values of this enum describe additional information about a touch point.
3643 \value Pen Indicates that the contact has been made by a designated pointing device (e.g. a pen) instead of a finger.
3649 Constructs a QTouchEvent::TouchPoint for use in a QTouchEvent.
3651 QTouchEvent::TouchPoint::TouchPoint(int id)
3652 : d(new QTouchEventTouchPointPrivate(id))
3656 \fn TouchPoint::TouchPoint(const TouchPoint &other)
3659 Constructs a copy of \a other.
3661 QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
3670 Destroys the QTouchEvent::TouchPoint.
3672 QTouchEvent::TouchPoint::~TouchPoint()
3674 if (d && !d->ref.deref())
3679 Returns the id number of this touch point.
3681 Do not assume that id numbers start at zero or that they are sequential.
3682 Such an assumption is often false due to the way the underlying drivers work.
3684 int QTouchEvent::TouchPoint::id() const
3690 Returns the current state of this touch point.
3692 Qt::TouchPointState QTouchEvent::TouchPoint::state() const
3694 return Qt::TouchPointState(int(d->state));
3698 Returns the position of this touch point, relative to the widget
3699 or QGraphicsItem that received the event.
3701 \sa startPos(), lastPos(), screenPos(), scenePos(), normalizedPos()
3703 QPointF QTouchEvent::TouchPoint::pos() const
3705 return d->rect.center();
3709 Returns the scene position of this touch point.
3711 The scene position is the position in QGraphicsScene coordinates
3712 if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
3713 reimplementation, and identical to the screen position for
3716 \sa startScenePos(), lastScenePos(), pos()
3718 QPointF QTouchEvent::TouchPoint::scenePos() const
3720 return d->sceneRect.center();
3724 Returns the screen position of this touch point.
3726 \sa startScreenPos(), lastScreenPos(), pos()
3728 QPointF QTouchEvent::TouchPoint::screenPos() const
3730 return d->screenRect.center();
3734 Returns the normalized position of this touch point.
3736 The coordinates are normalized to the size of the touch device,
3737 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
3739 \sa startNormalizedPos(), lastNormalizedPos(), pos()
3741 QPointF QTouchEvent::TouchPoint::normalizedPos() const
3743 return d->normalizedPos;
3747 Returns the starting position of this touch point, relative to the
3748 widget or QGraphicsItem that received the event.
3750 \sa pos(), lastPos()
3752 QPointF QTouchEvent::TouchPoint::startPos() const
3758 Returns the starting scene position of this touch point.
3760 The scene position is the position in QGraphicsScene coordinates
3761 if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
3762 reimplementation, and identical to the screen position for
3765 \sa scenePos(), lastScenePos()
3767 QPointF QTouchEvent::TouchPoint::startScenePos() const
3769 return d->startScenePos;
3773 Returns the starting screen position of this touch point.
3775 \sa screenPos(), lastScreenPos()
3777 QPointF QTouchEvent::TouchPoint::startScreenPos() const
3779 return d->startScreenPos;
3783 Returns the normalized starting position of this touch point.
3785 The coordinates are normalized to the size of the touch device,
3786 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
3788 \sa normalizedPos(), lastNormalizedPos()
3790 QPointF QTouchEvent::TouchPoint::startNormalizedPos() const
3792 return d->startNormalizedPos;
3796 Returns the position of this touch point from the previous touch
3797 event, relative to the widget or QGraphicsItem that received the event.
3799 \sa pos(), startPos()
3801 QPointF QTouchEvent::TouchPoint::lastPos() const
3807 Returns the scene position of this touch point from the previous
3810 The scene position is the position in QGraphicsScene coordinates
3811 if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
3812 reimplementation, and identical to the screen position for
3815 \sa scenePos(), startScenePos()
3817 QPointF QTouchEvent::TouchPoint::lastScenePos() const
3819 return d->lastScenePos;
3823 Returns the screen position of this touch point from the previous
3826 \sa screenPos(), startScreenPos()
3828 QPointF QTouchEvent::TouchPoint::lastScreenPos() const
3830 return d->lastScreenPos;
3834 Returns the normalized position of this touch point from the
3835 previous touch event.
3837 The coordinates are normalized to the size of the touch device,
3838 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
3840 \sa normalizedPos(), startNormalizedPos()
3842 QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const
3844 return d->lastNormalizedPos;
3848 Returns the rect for this touch point, relative to the widget
3849 or QGraphicsItem that received the event. The rect is centered
3850 around the point returned by pos().
3852 \note This function returns an empty rect if the device does not report touch point sizes.
3854 QRectF QTouchEvent::TouchPoint::rect() const
3860 Returns the rect for this touch point in scene coordinates.
3862 \note This function returns an empty rect if the device does not report touch point sizes.
3864 \sa scenePos(), rect()
3866 QRectF QTouchEvent::TouchPoint::sceneRect() const
3868 return d->sceneRect;
3872 Returns the rect for this touch point in screen coordinates.
3874 \note This function returns an empty rect if the device does not report touch point sizes.
3876 \sa screenPos(), rect()
3878 QRectF QTouchEvent::TouchPoint::screenRect() const
3880 return d->screenRect;
3884 Returns the pressure of this touch point. The return value is in
3885 the range 0.0 to 1.0.
3887 qreal QTouchEvent::TouchPoint::pressure() const
3893 Returns a velocity vector for this touch point.
3894 The vector is in the screen's coordinate system, using pixels per seconds for the magnitude.
3896 \note The returned vector is only valid if the touch device's capabilities include QTouchDevice::Velocity.
3898 \sa QTouchDevice::capabilities(), device()
3900 QVector2D QTouchEvent::TouchPoint::velocity() const
3906 Returns additional information about the touch point.
3908 \sa QTouchEvent::TouchPoint::InfoFlags
3910 QTouchEvent::TouchPoint::InfoFlags QTouchEvent::TouchPoint::flags() const
3917 Returns the raw, unfiltered positions for the touch point. The positions are in native screen coordinates.
3918 To get local coordinates you can use mapFromGlobal() of the QWindow returned by QTouchEvent::window().
3920 \note Returns an empty vector if the touch device's capabilities do not include QTouchDevice::RawPositions.
3922 \note Native screen coordinates refer to the native orientation of the screen which, in case of
3923 mobile devices, is typically portrait. This means that on systems capable of screen orientation
3924 changes the positions in this list will not reflect the current orientation (unlike pos(),
3925 screenPos(), etc.) and will always be reported in the native orientation.
3927 \sa QTouchDevice::capabilities(), device(), window()
3929 QVector<QPointF> QTouchEvent::TouchPoint::rawScreenPositions() const
3931 return d->rawScreenPositions;
3935 void QTouchEvent::TouchPoint::setId(int id)
3937 if (d->ref.load() != 1)
3943 void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state)
3945 if (d->ref.load() != 1)
3951 void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
3953 if (d->ref.load() != 1)
3955 d->rect.moveCenter(pos);
3959 void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
3961 if (d->ref.load() != 1)
3963 d->sceneRect.moveCenter(scenePos);
3967 void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
3969 if (d->ref.load() != 1)
3971 d->screenRect.moveCenter(screenPos);
3975 void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
3977 if (d->ref.load() != 1)
3979 d->normalizedPos = normalizedPos;
3983 void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
3985 if (d->ref.load() != 1)
3987 d->startPos = startPos;
3991 void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
3993 if (d->ref.load() != 1)
3995 d->startScenePos = startScenePos;
3999 void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
4001 if (d->ref.load() != 1)
4003 d->startScreenPos = startScreenPos;
4007 void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos)
4009 if (d->ref.load() != 1)
4011 d->startNormalizedPos = startNormalizedPos;
4015 void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
4017 if (d->ref.load() != 1)
4019 d->lastPos = lastPos;
4023 void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos)
4025 if (d->ref.load() != 1)
4027 d->lastScenePos = lastScenePos;
4031 void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
4033 if (d->ref.load() != 1)
4035 d->lastScreenPos = lastScreenPos;
4039 void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos)
4041 if (d->ref.load() != 1)
4043 d->lastNormalizedPos = lastNormalizedPos;
4047 void QTouchEvent::TouchPoint::setRect(const QRectF &rect)
4049 if (d->ref.load() != 1)
4055 void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect)
4057 if (d->ref.load() != 1)
4059 d->sceneRect = sceneRect;
4063 void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect)
4065 if (d->ref.load() != 1)
4067 d->screenRect = screenRect;
4071 void QTouchEvent::TouchPoint::setPressure(qreal pressure)
4073 if (d->ref.load() != 1)
4075 d->pressure = pressure;
4079 void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v)
4081 if (d->ref.load() != 1)
4087 void QTouchEvent::TouchPoint::setRawScreenPositions(const QVector<QPointF> &positions)
4089 if (d->ref.load() != 1)
4091 d->rawScreenPositions = positions;
4097 void QTouchEvent::TouchPoint::setFlags(InfoFlags flags)
4099 if (d->ref.load() != 1)
4105 \fn TouchPoint &TouchPoint::operator=(const TouchPoint &other)
4110 \fn void QTouchEvent::TouchPoint::swap(TouchPoint &other);
4115 \class QScrollPrepareEvent
4120 \brief The QScrollPrepareEvent class is send in preparation of a scrolling.
4122 The scroll prepare event is send before scrolling (usually by QScroller) is started.
4123 The object receiving this event should set viewportSize, maxContentPos and contentPos.
4124 It also should accept this event to indicate that scrolling should be started.
4126 It is not guaranteed that a QScrollEvent will be send after an acceepted
4127 QScrollPrepareEvent, e.g. in a case where the maximum content position is (0,0).
4129 \sa QScrollEvent, QScroller
4133 Creates new QScrollPrepareEvent
4134 The \a startPos is the position of a touch or mouse event that started the scrolling.
4136 QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos)
4137 : QEvent(QEvent::ScrollPrepare), m_target(0), m_startPos(startPos)
4142 Destroys QScrollEvent.
4144 QScrollPrepareEvent::~QScrollPrepareEvent()
4149 Returns the position of the touch or mouse event that started the scrolling.
4151 QPointF QScrollPrepareEvent::startPos() const
4157 Returns size of the area that is to be scrolled as set by setViewportSize
4159 \sa setViewportSize()
4161 QSizeF QScrollPrepareEvent::viewportSize() const
4163 return m_viewportSize;
4167 Returns the range of coordinates for the content as set by setContentPosRange().
4169 QRectF QScrollPrepareEvent::contentPosRange() const
4171 return m_contentPosRange;
4175 Returns the current position of the content as set by setContentPos.
4177 QPointF QScrollPrepareEvent::contentPos() const
4179 return m_contentPos;
4184 Sets the size of the area that is to be scrolled to \a size.
4188 void QScrollPrepareEvent::setViewportSize(const QSizeF &size)
4190 m_viewportSize = size;
4194 Sets the range of content coordinates to \a rect.
4196 \sa contentPosRange()
4198 void QScrollPrepareEvent::setContentPosRange(const QRectF &rect)
4200 m_contentPosRange = rect;
4204 Sets the current content position to \a pos.
4208 void QScrollPrepareEvent::setContentPos(const QPointF &pos)
4220 \brief The QScrollEvent class is send when scrolling.
4222 The scroll event is send to indicate that the receiver should be scrolled.
4223 Usually the receiver should be something visual like QWidget or QGraphicsObject.
4225 Some care should be taken that no conflicting QScrollEvents are sent from two
4226 sources. Using QScroller::scrollTo is save however.
4228 \sa QScrollPrepareEvent, QScroller
4232 \enum QScrollEvent::ScrollState
4234 This enum describes the states a scroll event can have.
4236 \value ScrollStarted Set for the first scroll event of a scroll activity.
4238 \value ScrollUpdated Set for all but the first and the last scroll event of a scroll activity.
4240 \value ScrollFinished Set for the last scroll event of a scroll activity.
4242 \sa QScrollEvent::scrollState()
4246 Creates a new QScrollEvent
4247 \a contentPos is the new content position, \a overshootDistance is the
4248 new overshoot distance while \a scrollState indicates if this scroll
4249 event is the first one, the last one or some event in between.
4251 QScrollEvent::QScrollEvent(const QPointF &contentPos, const QPointF &overshootDistance, ScrollState scrollState)
4252 : QEvent(QEvent::Scroll), m_contentPos(contentPos), m_overshoot(overshootDistance), m_state(scrollState)
4257 Destroys QScrollEvent.
4259 QScrollEvent::~QScrollEvent()
4264 Returns the new scroll position.
4266 QPointF QScrollEvent::contentPos() const
4268 return m_contentPos;
4272 Returns the new overshoot distance.
4273 See QScroller for an explanation of the term overshoot.
4277 QPointF QScrollEvent::overshootDistance() const
4283 Returns the current scroll state as a combination of ScrollStateFlag values.
4284 ScrollStarted (or ScrollFinished) will be set, if this scroll event is the first (or last) event in a scrolling activity.
4285 Please note that both values can be set at the same time, if the activity consists of a single QScrollEvent.
4286 All other scroll events in between will have their state set to ScrollUpdated.
4288 A widget could for example revert selections when scrolling is started and stopped.
4290 QScrollEvent::ScrollState QScrollEvent::scrollState() const
4296 Creates a new QScreenOrientationChangeEvent
4297 \a orientation is the new orientation of the screen.
4299 QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation screenOrientation)
4300 : QEvent(QEvent::OrientationChange), m_screen(screen), m_orientation(screenOrientation)
4305 Destroys QScreenOrientationChangeEvent.
4307 QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent()
4312 Returns the screen whose orientation changed.
4314 QScreen *QScreenOrientationChangeEvent::screen() const
4320 Returns the orientation of the screen.
4322 Qt::ScreenOrientation QScreenOrientationChangeEvent::orientation() const
4324 return m_orientation;