1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include "private/qguiapplication_p.h"
45 #include "private/qevent_p.h"
46 #include "private/qkeysequence_p.h"
48 #include "qmimedata.h"
49 #include "private/qdnd_p.h"
60 \brief The QInputEvent class is the base class for events that
67 QInputEvent::QInputEvent(Type type, Qt::KeyboardModifiers modifiers)
68 : QEvent(type), modState(modifiers), ts(0)
74 QInputEvent::~QInputEvent()
79 \fn Qt::KeyboardModifiers QInputEvent::modifiers() const
81 Returns the keyboard modifier flags that existed immediately
82 before the event occurred.
84 \sa QApplication::keyboardModifiers()
87 /*! \fn void QInputEvent::setModifiers(Qt::KeyboardModifiers modifiers)
91 Sets the keyboard modifiers flags for this event.
98 \brief The QMouseEvent class contains parameters that describe a mouse event.
100 Mouse events occur when a mouse button is pressed or released
101 inside a widget, or when the mouse cursor is moved.
103 Mouse move events will occur only when a mouse button is pressed
104 down, unless mouse tracking has been enabled with
105 QWidget::setMouseTracking().
107 Qt automatically grabs the mouse when a mouse button is pressed
108 inside a widget; the widget will continue to receive mouse events
109 until the last mouse button is released.
111 A mouse event contains a special accept flag that indicates
112 whether the receiver wants the event. You should call ignore() if
113 the mouse event is not handled by your widget. A mouse event is
114 propagated up the parent widget chain until a widget accepts it
115 with accept(), or an event filter consumes it.
117 \note If a mouse event is propagated to a \l{QWidget}{widget} for
118 which Qt::WA_NoMousePropagation has been set, that mouse event
119 will not be propagated further up the parent widget chain.
121 The state of the keyboard modifier keys can be found by calling the
122 \l{QInputEvent::modifiers()}{modifiers()} function, inherited from
125 The functions pos(), x(), and y() give the cursor position
126 relative to the widget that receives the mouse event. If you
127 move the widget as a result of the mouse event, use the global
128 position returned by globalPos() to avoid a shaking motion.
130 The QWidget::setEnabled() function can be used to enable or
131 disable mouse and keyboard events for a widget.
133 Reimplement the QWidget event handlers, QWidget::mousePressEvent(),
134 QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(),
135 and QWidget::mouseMoveEvent() to receive mouse events in your own
138 \sa QWidget::setMouseTracking() QWidget::grabMouse()
143 Constructs a mouse event object.
145 The \a type parameter must be one of QEvent::MouseButtonPress,
146 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
147 or QEvent::MouseMove.
149 The \a localPos is the mouse cursor's position relative to the
150 receiving widget or item. The window position is set to the same value
152 The \a button that caused the event is given as a value from
153 the Qt::MouseButton enum. If the event \a type is
154 \l MouseMove, the appropriate button for this event is Qt::NoButton.
155 The mouse and keyboard states at the time of the event are specified by
156 \a buttons and \a modifiers.
158 The screenPos() is initialized to QCursor::pos(), which may not
159 be appropriate. Use the other constructor to specify the global
162 QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
163 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
164 : QInputEvent(type, modifiers), l(localPos), w(localPos), b(button), mouseState(buttons)
171 Constructs a mouse event object.
173 The \a type parameter must be QEvent::MouseButtonPress,
174 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
175 or QEvent::MouseMove.
177 The \a localPos is the mouse cursor's position relative to the
178 receiving widget or item. The cursor's position in screen coordinates is
179 specified by \a screenPos. The window position is set to the same value
180 as \a localPos. The \a button that caused the event is
181 given as a value from the \l Qt::MouseButton enum. If the event \a
182 type is \l MouseMove, the appropriate button for this event is
183 Qt::NoButton. \a buttons is the state of all buttons at the
184 time of the event, \a modifiers the state of all keyboard
188 QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &screenPos,
189 Qt::MouseButton button, Qt::MouseButtons buttons,
190 Qt::KeyboardModifiers modifiers)
191 : QInputEvent(type, modifiers), l(localPos), w(localPos), s(screenPos), b(button), mouseState(buttons)
195 Constructs a mouse event object.
197 The \a type parameter must be QEvent::MouseButtonPress,
198 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
199 or QEvent::MouseMove.
201 The \a pos is the mouse cursor's position relative to the
202 receiving widget. The cursor's position in global coordinates is
203 specified by \a globalPos. The \a button that caused the event is
204 given as a value from the \l Qt::MouseButton enum. If the event \a
205 type is \l MouseMove, the appropriate button for this event is
206 Qt::NoButton. \a buttons is the state of all buttons at the
207 time of the event, \a modifiers the state of all keyboard
211 QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos,
212 Qt::MouseButton button, Qt::MouseButtons buttons,
213 Qt::KeyboardModifiers modifiers)
214 : QInputEvent(type, modifiers), l(localPos), w(windowPos), s(screenPos), b(button), mouseState(buttons)
220 QMouseEvent::~QMouseEvent()
226 \fn QPointF QMouseEvent::localPos() const
230 Returns the position of the mouse cursor as a QPointF, relative to the
231 widget or item that received the event.
233 If you move the widget as a result of the mouse event, use the
234 screen position returned by screenPos() to avoid a shaking
237 \sa x() y() windowPos() screenPos()
241 \fn QPointF QMouseEvent::windowPos() const
245 Returns the position of the mouse cursor as a QPointF, relative to the
246 window that received the event.
248 If you move the widget as a result of the mouse event, use the
249 global position returned by globalPos() to avoid a shaking
252 \sa x() y() pos() localPos() screenPos()
256 \fn QPointF QMouseEvent::screenPos() const
260 Returns the position of the mouse cursor as a QPointF, relative to the
261 screen that received the event.
263 \sa x() y() pos() localPos() screenPos()
267 \fn const QPoint &QMouseEvent::pos() const
269 Returns the position of the mouse cursor, relative to the widget
270 that received the event.
272 If you move the widget as a result of the mouse event, use the
273 global position returned by globalPos() to avoid a shaking
276 \sa x() y() globalPos()
280 \fn const QPoint &QMouseEvent::globalPos() const
282 Returns the global position of the mouse cursor \e{at the time
283 of the event}. This is important on asynchronous window systems
284 like X11. Whenever you move your widgets around in response to
285 mouse events, globalPos() may differ a lot from the current
286 pointer position QCursor::pos(), and from
287 QWidget::mapToGlobal(pos()).
289 \sa globalX() globalY()
293 \fn int QMouseEvent::x() const
295 Returns the x position of the mouse cursor, relative to the
296 widget that received the event.
302 \fn int QMouseEvent::y() const
304 Returns the y position of the mouse cursor, relative to the
305 widget that received the event.
311 \fn int QMouseEvent::globalX() const
313 Returns the global x position of the mouse cursor at the time of
316 \sa globalY() globalPos()
320 \fn int QMouseEvent::globalY() const
322 Returns the global y position of the mouse cursor at the time of
325 \sa globalX() globalPos()
329 \fn Qt::MouseButton QMouseEvent::button() const
331 Returns the button that caused the event.
333 Note that the returned value is always Qt::NoButton for mouse
336 \sa buttons() Qt::MouseButton
340 \fn Qt::MouseButton QMouseEvent::buttons() const
342 Returns the button state when the event was generated. The button
343 state is a combination of Qt::LeftButton, Qt::RightButton,
344 Qt::MidButton using the OR operator. For mouse move events,
345 this is all buttons that are pressed down. For mouse press and
346 double click events this includes the button that caused the
347 event. For mouse release events this excludes the button that
350 \sa button() Qt::MouseButton
357 \brief The QHoverEvent class contains parameters that describe a mouse event.
359 Mouse events occur when a mouse cursor is moved into, out of, or within a
360 widget, and if the widget has the Qt::WA_Hover attribute.
362 The function pos() gives the current cursor position, while oldPos() gives
363 the old mouse position.
365 There are a few similarities between the events QEvent::HoverEnter
366 and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave.
367 However, they are slightly different because we do an update() in the event
368 handler of HoverEnter and HoverLeave.
370 QEvent::HoverMove is also slightly different from QEvent::MouseMove. Let us
371 consider a top-level window A containing a child B which in turn contains a
372 child C (all with mouse tracking enabled):
374 \image hoverevents.png
376 Now, if you move the cursor from the top to the bottom in the middle of A,
377 you will get the following QEvent::MouseMove events:
385 You will get the same events for QEvent::HoverMove, except that the event
386 always propagates to the top-level regardless whether the event is accepted
387 or not. It will only stop propagating with the Qt::WA_NoMousePropagation
390 In this case the events will occur in the following way:
394 \o A::HoverMove, B::HoverMove
395 \o A::HoverMove, B::HoverMove, C::HoverMove
401 \fn const QPoint &QHoverEvent::pos() const
403 Returns the position of the mouse cursor, relative to the widget
404 that received the event.
406 On QEvent::HoverLeave events, this position will always be
413 \fn const QPoint &QHoverEvent::oldPos() const
415 Returns the previous position of the mouse cursor, relative to the widget
416 that received the event. If there is no previous position, oldPos() will
417 return the same position as pos().
419 On QEvent::HoverEnter events, this position will always be
426 Constructs a hover event object.
428 The \a type parameter must be QEvent::HoverEnter,
429 QEvent::HoverLeave, or QEvent::HoverMove.
431 The \a pos is the current mouse cursor's position relative to the
432 receiving widget, while \a oldPos is the previous mouse cursor's
433 position relative to the receiving widget.
435 QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers)
436 : QInputEvent(type, modifiers), p(pos), op(oldPos)
443 QHoverEvent::~QHoverEvent()
450 \brief The QWheelEvent class contains parameters that describe a wheel event.
454 Wheel events are sent to the widget under the mouse cursor, but
455 if that widget does not handle the event they are sent to the
456 focus widget. Wheel events are generated for both mouse wheels
457 and trackpad scroll gestures. There are two ways to read the
458 wheel event delta: angleDelta() returns the delta in wheel
459 degrees. This value is always provided. pixelDelta() returns
460 the delta in screen pixels and is available on platforms that
461 have high-resolution trackpads, such as Mac OS X.
463 The functions pos() and globalPos() return the mouse cursor's
464 location at the time of the event.
466 A wheel event contains a special accept flag that indicates
467 whether the receiver wants the event. You should call ignore() if
468 you do not handle the wheel event; this ensures that it will be
469 sent to the parent widget.
471 The QWidget::setEnabled() function can be used to enable or
472 disable mouse and keyboard events for a widget.
474 The event handler QWidget::wheelEvent() receives wheel events.
476 \sa QMouseEvent QWidget::grabMouse()
480 \fn Qt::MouseButtons QWheelEvent::buttons() const
482 Returns the mouse state when the event occurred.
486 \fn Qt::Orientation QWheelEvent::orientation() const
488 Returns the wheel's orientation.
493 Constructs a wheel event object.
495 Use the QPoint-based constructor instead.
497 The position, \a pos, is the location of the mouse cursor within
498 the widget. The globalPos() is initialized to QCursor::pos()
499 which is usually, but not always, correct.
500 Use the other constructor if you need to specify the global
503 The \a buttons describe the state of the mouse buttons at the time
504 of the event, \a delta contains the rotation distance,
505 \a modifiers holds the keyboard modifier flags at the time of the
506 event, and \a orient holds the wheel's orientation.
508 \sa pos() pixelDelta() angleDelta() state()
510 #ifndef QT_NO_WHEELEVENT
511 QWheelEvent::QWheelEvent(const QPointF &pos, int delta,
512 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
513 Qt::Orientation orient)
514 : QInputEvent(Wheel, modifiers), p(pos), qt4D(delta), qt4O(orient), mouseState(buttons)
522 QWheelEvent::~QWheelEvent()
528 Constructs a wheel event object.
530 Use the QPoint-based constructor instead.
532 The \a pos provides the location of the mouse cursor
533 within the widget. The position in global coordinates is specified
534 by \a globalPos. \a delta contains the rotation distance, \a modifiers
535 holds the keyboard modifier flags at the time of the event, and
536 \a orient holds the wheel's orientation.
539 \sa pos() pixelDelta() angleDelta() state()
541 QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta,
542 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
543 Qt::Orientation orient)
544 : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), qt4D(delta), qt4O(orient), mouseState(buttons)
548 Constructs a wheel event object.
550 The \a pos provides the location of the mouse cursor
551 within the window. The position in global coordinates is specified
552 by \a globalPos. \pixelDelta contains the scrolling distance
553 in pixels on screen, \a angleDelta contains the wheel rotation distance.
554 \pixelDelta is optional and can be null.
556 \a modifiers holds the keyboard modifier flags at the time of the event.
558 \a pixelDelta contains the scrolling delta in pixels,
559 \a angleDelta contains the rotation distance, and
560 \a orient holds the wheel's orientation.
562 \sa pos() globalPos() delta() state()
565 QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
566 QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
567 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
568 : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta),
569 angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons)
573 #endif // QT_NO_WHEELEVENT
576 \fn QPoint QWheelEvent::pixelDelta() const
578 Returns the scrolling distance in pixels on screen. This value is
579 provided on platforms that support high-resolution pixel-based
580 delta values, such as Mac OS X. The value should be used directly
581 to scroll content on screen.
585 \snippet doc/src/snippets/code/src_gui_kernel_qevent.cpp 0
589 \fn QPoint QWheelEvent::angleDelta() const
591 Returns the distance that the wheel is rotated, in eighths of a
592 degree. A positive value indicates that the wheel was rotated
593 forwards away from the user; a negative value indicates that the
594 wheel was rotated backwards toward the user.
596 Most mouse types work in steps of 15 degrees, in which case the
597 delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
599 However, some mice have finer-resolution wheels and send delta values
600 that are less than 120 units (less than 15 degrees). To support this
601 possibility, you can either cumulatively add the delta values from events
602 until the value of 120 is reached, then scroll the widget, or you can
603 partially scroll the widget in response to each wheel event.
607 \snippet doc/src/snippets/code/src_gui_kernel_qevent.cpp 0
611 \fn int QWheelEvent::delta() const
613 This function has been deprecated, use pixelDelta() or angleDelta() instead.
617 \fn const QPoint &QWheelEvent::pos() const
619 Returns the position of the mouse cursor relative to the widget
620 that received the event.
622 If you move your widgets around in response to mouse events,
623 use globalPos() instead of this function.
625 \sa x() y() globalPos()
629 \fn int QWheelEvent::x() const
631 Returns the x position of the mouse cursor, relative to the
632 widget that received the event.
638 \fn int QWheelEvent::y() const
640 Returns the y position of the mouse cursor, relative to the
641 widget that received the event.
648 \fn const QPoint &QWheelEvent::globalPos() const
650 Returns the global position of the mouse pointer \e{at the time
651 of the event}. This is important on asynchronous window systems
652 such as X11; whenever you move your widgets around in response to
653 mouse events, globalPos() can differ a lot from the current
654 cursor position returned by QCursor::pos().
656 \sa globalX() globalY()
660 \fn int QWheelEvent::globalX() const
662 Returns the global x position of the mouse cursor at the time of
665 \sa globalY() globalPos()
669 \fn int QWheelEvent::globalY() const
671 Returns the global y position of the mouse cursor at the time of
674 \sa globalX() globalPos()
679 \brief The QKeyEvent class describes a key event.
683 Key events are sent to the widget with keyboard input focus
684 when keys are pressed or released.
686 A key event contains a special accept flag that indicates whether
687 the receiver will handle the key event. You should call ignore()
688 if the key press or release event is not handled by your widget.
689 A key event is propagated up the parent widget chain until a
690 widget accepts it with accept() or an event filter consumes it.
691 Key events for multimedia keys are ignored by default. You should
692 call accept() if your widget handles those events.
694 The QWidget::setEnable() function can be used to enable or disable
695 mouse and keyboard events for a widget.
697 The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(),
698 QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent()
701 \sa QFocusEvent, QWidget::grabKeyboard()
705 Constructs a key event object.
707 The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
708 or QEvent::ShortcutOverride.
710 Int \a key is the code for the Qt::Key that the event loop should listen
711 for. If \a key is 0, the event is not a result of a known key; for
712 example, it may be the result of a compose sequence or keyboard macro.
713 The \a modifiers holds the keyboard modifiers, and the given \a text
714 is the Unicode text that the key generated. If \a autorep is true,
715 isAutoRepeat() will be true. \a count is the number of keys involved
718 QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
719 bool autorep, ushort count)
720 : QInputEvent(type, modifiers), txt(text), k(key), c(count), autor(autorep)
727 QKeyEvent::~QKeyEvent()
734 QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
735 quint32 nativeScanCode, quint32 nativeVirtualKey,
736 quint32 nativeModifiers,
737 const QString& text, bool autorep, ushort count)
739 return new QKeyEventEx(type, key, modifiers, text, autorep, count,
740 nativeScanCode, nativeVirtualKey, nativeModifiers);
744 \fn bool QKeyEvent::hasExtendedInfo() const
751 Returns the native scan code of the key event. If the key event
752 does not contain this data 0 is returned.
754 Note: The native scan code may be 0, even if the key event contains
755 extended information.
757 Note: On Mac OS/X, this function is not useful, because there is no
758 way to get the scan code from Carbon or Cocoa. The function always
759 returns 1 (or 0 in the case explained above).
761 quint32 QKeyEvent::nativeScanCode() const
763 return (reinterpret_cast<const QKeyEvent*>(d) != this
764 ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nScanCode);
770 Returns the native virtual key, or key sym of the key event.
771 If the key event does not contain this data 0 is returned.
773 Note: The native virtual key may be 0, even if the key event contains extended information.
775 quint32 QKeyEvent::nativeVirtualKey() const
777 return (reinterpret_cast<const QKeyEvent*>(d) != this
778 ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nVirtualKey);
784 Returns the native modifiers of a key event.
785 If the key event does not contain this data 0 is returned.
787 Note: The native modifiers may be 0, even if the key event contains extended information.
789 quint32 QKeyEvent::nativeModifiers() const
791 return (reinterpret_cast<const QKeyEvent*>(d) != this
792 ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nModifiers);
797 Creates an extended key event object, which in addition to the normal key event data, also
798 contains the native scan code, virtual key and modifiers. This extra data is used by the
799 shortcut system, to determine which shortcuts to trigger.
801 QKeyEventEx::QKeyEventEx(Type type, int key, Qt::KeyboardModifiers modifiers,
802 const QString &text, bool autorep, ushort count,
803 quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers)
804 : QKeyEvent(type, key, modifiers, text, autorep, count),
805 nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers)
807 d = reinterpret_cast<QEventPrivate*>(this);
812 Creates a copy of an other extended key event.
814 QKeyEventEx::QKeyEventEx(const QKeyEventEx &other)
815 : QKeyEvent(QEvent::Type(other.t), other.k, other.modState, other.txt, other.autor, other.c),
816 nScanCode(other.nScanCode), nVirtualKey(other.nVirtualKey), nModifiers(other.nModifiers)
818 d = reinterpret_cast<QEventPrivate*>(this);
824 QKeyEventEx::~QKeyEventEx()
829 \fn int QKeyEvent::key() const
831 Returns the code of the key that was pressed or released.
833 See \l Qt::Key for the list of keyboard codes. These codes are
834 independent of the underlying window system. Note that this
835 function does not distinguish between capital and non-capital
836 letters, use the text() function (returning the Unicode text the
837 key generated) for this purpose.
839 A value of either 0 or Qt::Key_unknown means that the event is not
840 the result of a known key; for example, it may be the result of
841 a compose sequence, a keyboard macro, or due to key event
844 \sa Qt::WA_KeyCompression
848 \fn QString QKeyEvent::text() const
850 Returns the Unicode text that this key generated. The text
851 returned can be an empty string in cases
852 where modifier keys, such as Shift, Control, Alt, and Meta,
853 are being pressed or released. In such cases key() will contain
856 \sa Qt::WA_KeyCompression
860 Returns the keyboard modifier flags that existed immediately
861 after the event occurred.
863 \warning This function cannot always be trusted. The user can
864 confuse it by pressing both \key{Shift} keys simultaneously and
865 releasing one of them, for example.
867 \sa QApplication::keyboardModifiers()
869 //###### We must check with XGetModifierMapping
870 Qt::KeyboardModifiers QKeyEvent::modifiers() const
872 if (key() == Qt::Key_Shift)
873 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ShiftModifier);
874 if (key() == Qt::Key_Control)
875 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ControlModifier);
876 if (key() == Qt::Key_Alt)
877 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::AltModifier);
878 if (key() == Qt::Key_Meta)
879 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::MetaModifier);
880 return QInputEvent::modifiers();
883 #ifndef QT_NO_SHORTCUT
885 \fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const
888 Returns true if the key event matches the given standard \a key;
889 otherwise returns false.
891 bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const
893 uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier); //The keypad modifier should not make a difference
894 const uint platform = QKeySequencePrivate::currentKeyPlatforms();
897 uint N = QKeySequencePrivate::numberOfKeyBindings;
901 while (first <= last) {
902 int mid = (first + last) / 2;
903 QKeyBinding midVal = QKeySequencePrivate::keyBindings[mid];
905 if (searchkey > midVal.shortcut){
906 first = mid + 1; // Search in top half
908 else if (searchkey < midVal.shortcut){
909 last = mid - 1; // Search in bottom half
912 //found correct shortcut value, now we must check for platform match
913 if ((midVal.platform & platform) && (midVal.standardKey == matchKey)) {
915 } else { //We may have several equal values for different platforms, so we must search in both directions
918 for ( unsigned int i = mid + 1 ; i < N - 1 ; ++i) {
919 QKeyBinding current = QKeySequencePrivate::keyBindings[i];
920 if (current.shortcut != searchkey)
922 else if (current.platform & platform && current.standardKey == matchKey)
927 for ( int i = mid - 1 ; i >= 0 ; --i) {
928 QKeyBinding current = QKeySequencePrivate::keyBindings[i];
929 if (current.shortcut != searchkey)
931 else if (current.platform & platform && current.standardKey == matchKey)
934 return false; //we could not find it among the matching keySequences
938 return false; //we could not find matching keySequences at all
940 #endif // QT_NO_SHORTCUT
944 \fn bool QKeyEvent::isAutoRepeat() const
946 Returns true if this event comes from an auto-repeating key;
947 returns false if it comes from an initial key press.
949 Note that if the event is a multiple-key compressed event that is
950 partly due to auto-repeat, this function could return either true
951 or false indeterminately.
955 \fn int QKeyEvent::count() const
957 Returns the number of keys involved in this event. If text()
958 is not empty, this is simply the length of the string.
960 \sa Qt::WA_KeyCompression
965 \brief The QFocusEvent class contains event parameters for widget focus
970 Focus events are sent to widgets when the keyboard input focus
971 changes. Focus events occur due to mouse actions, key presses
972 (such as \gui{Tab} or \gui{Backtab}), the window system, popup
973 menus, keyboard shortcuts, or other application-specific reasons.
974 The reason for a particular focus event is returned by reason()
975 in the appropriate event handler.
977 The event handlers QWidget::focusInEvent(),
978 QWidget::focusOutEvent(), QGraphicsItem::focusInEvent and
979 QGraphicsItem::focusOutEvent() receive focus events.
981 \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus}
985 Constructs a focus event object.
987 The \a type parameter must be either QEvent::FocusIn or
988 QEvent::FocusOut. The \a reason describes the cause of the change
991 QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason)
992 : QEvent(type), m_reason(reason)
998 QFocusEvent::~QFocusEvent()
1003 Returns the reason for this focus event.
1005 Qt::FocusReason QFocusEvent::reason() const
1011 \fn bool QFocusEvent::gotFocus() const
1013 Returns true if type() is QEvent::FocusIn; otherwise returns
1018 \fn bool QFocusEvent::lostFocus() const
1020 Returns true if type() is QEvent::FocusOut; otherwise returns
1027 \brief The QPaintEvent class contains event parameters for paint events.
1031 Paint events are sent to widgets that need to update themselves,
1032 for instance when part of a widget is exposed because a covering
1035 The event contains a region() that needs to be updated, and a
1036 rect() that is the bounding rectangle of that region. Both are
1037 provided because many widgets can't make much use of region(),
1038 and rect() can be much faster than region().boundingRect().
1040 \section1 Automatic Clipping
1042 Painting is clipped to region() during the processing of a paint
1043 event. This clipping is performed by Qt's paint system and is
1044 independent of any clipping that may be applied to a QPainter used to
1045 draw on the paint device.
1047 As a result, the value returned by QPainter::clipRegion() on
1048 a newly-constructed QPainter will not reflect the clip region that is
1049 used by the paint system.
1051 \sa QPainter, QWidget::update(), QWidget::repaint(),
1052 QWidget::paintEvent()
1056 Constructs a paint event object with the region that needs to
1057 be updated. The region is specified by \a paintRegion.
1059 QPaintEvent::QPaintEvent(const QRegion& paintRegion)
1060 : QEvent(Paint), m_rect(paintRegion.boundingRect()), m_region(paintRegion), m_erased(false)
1064 Constructs a paint event object with the rectangle that needs
1065 to be updated. The region is specified by \a paintRect.
1067 QPaintEvent::QPaintEvent(const QRect &paintRect)
1068 : QEvent(Paint), m_rect(paintRect),m_region(paintRect), m_erased(false)
1075 QPaintEvent::~QPaintEvent()
1080 \fn const QRect &QPaintEvent::rect() const
1082 Returns the rectangle that needs to be updated.
1084 \sa region() QPainter::setClipRect()
1088 \fn const QRegion &QPaintEvent::region() const
1090 Returns the region that needs to be updated.
1092 \sa rect() QPainter::setClipRegion()
1096 QUpdateLaterEvent::QUpdateLaterEvent(const QRegion& paintRegion)
1097 : QEvent(UpdateLater), m_region(paintRegion)
1101 QUpdateLaterEvent::~QUpdateLaterEvent()
1107 \brief The QMoveEvent class contains event parameters for move events.
1111 Move events are sent to widgets that have been moved to a new
1112 position relative to their parent.
1114 The event handler QWidget::moveEvent() receives move events.
1116 \sa QWidget::move(), QWidget::setGeometry()
1120 Constructs a move event with the new and old widget positions,
1121 \a pos and \a oldPos respectively.
1123 QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos)
1124 : QEvent(Move), p(pos), oldp(oldPos)
1130 QMoveEvent::~QMoveEvent()
1135 \fn const QPoint &QMoveEvent::pos() const
1137 Returns the new position of the widget. This excludes the window
1138 frame for top level widgets.
1142 \fn const QPoint &QMoveEvent::oldPos() const
1144 Returns the old position of the widget.
1149 \brief The QExposeEvent class contains event parameters for expose events.
1153 Expose events are sent to widgets when an area of the widget is invalidated
1154 and needs to be flushed from the backing store.
1156 The event handler QWindow::exposeEvent() receives expose events.
1158 QExposeEvent::QExposeEvent(const QRegion &exposeRegion)
1167 QExposeEvent::~QExposeEvent()
1173 \brief The QResizeEvent class contains event parameters for resize events.
1177 Resize events are sent to widgets that have been resized.
1179 The event handler QWidget::resizeEvent() receives resize events.
1181 \sa QWidget::resize() QWidget::setGeometry()
1185 Constructs a resize event with the new and old widget sizes, \a
1186 size and \a oldSize respectively.
1188 QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
1189 : QEvent(Resize), s(size), olds(oldSize)
1195 QResizeEvent::~QResizeEvent()
1200 \fn const QSize &QResizeEvent::size() const
1202 Returns the new size of the widget. This is the same as
1207 \fn const QSize &QResizeEvent::oldSize() const
1209 Returns the old size of the widget.
1215 \brief The QCloseEvent class contains parameters that describe a close event.
1219 Close events are sent to widgets that the user wants to close,
1220 usually by choosing "Close" from the window menu, or by clicking
1221 the \gui{X} title bar button. They are also sent when you call
1222 QWidget::close() to close a widget programmatically.
1224 Close events contain a flag that indicates whether the receiver
1225 wants the widget to be closed or not. When a widget accepts the
1226 close event, it is hidden (and destroyed if it was created with
1227 the Qt::WA_DeleteOnClose flag). If it refuses to accept the close
1228 event nothing happens. (Under X11 it is possible that the window
1229 manager will forcibly close the window; but at the time of writing
1230 we are not aware of any window manager that does this.)
1232 The event handler QWidget::closeEvent() receives close events. The
1233 default implementation of this event handler accepts the close
1234 event. If you do not want your widget to be hidden, or want some
1235 special handing, you should reimplement the event handler and
1238 The \l{mainwindows/application#close event handler}{closeEvent() in the
1239 Application example} shows a close event handler that
1240 asks whether to save a document before closing.
1242 If you want the widget to be deleted when it is closed, create it
1243 with the Qt::WA_DeleteOnClose flag. This is very useful for
1244 independent top-level windows in a multi-window application.
1246 \l{QObject}s emits the \l{QObject::destroyed()}{destroyed()}
1247 signal when they are deleted.
1249 If the last top-level window is closed, the
1250 QApplication::lastWindowClosed() signal is emitted.
1252 The isAccepted() function returns true if the event's receiver has
1253 agreed to close the widget; call accept() to agree to close the
1254 widget and call ignore() if the receiver of this event does not
1255 want the widget to be closed.
1257 \sa QWidget::close(), QWidget::hide(), QObject::destroyed(),
1258 QCoreApplication::exec(), QCoreApplication::quit(),
1259 QApplication::lastWindowClosed()
1263 Constructs a close event object.
1267 QCloseEvent::QCloseEvent()
1273 QCloseEvent::~QCloseEvent()
1278 \class QIconDragEvent
1279 \brief The QIconDragEvent class indicates that a main icon drag has begun.
1283 Icon drag events are sent to widgets when the main icon of a window
1284 has been dragged away. On Mac OS X, this happens when the proxy
1285 icon of a window is dragged off the title bar.
1287 It is normal to begin using drag and drop in response to this
1290 \sa {Drag and Drop}, QMimeData, QDrag
1294 Constructs an icon drag event object with the accept flag set to
1299 QIconDragEvent::QIconDragEvent()
1304 QIconDragEvent::~QIconDragEvent()
1309 \class QContextMenuEvent
1310 \brief The QContextMenuEvent class contains parameters that describe a context menu event.
1314 Context menu events are sent to widgets when a user performs
1315 an action associated with opening a context menu.
1316 The actions required to open context menus vary between platforms;
1317 for example, on Windows, pressing the menu button or clicking the
1318 right mouse button will cause this event to be sent.
1320 When this event occurs it is customary to show a QMenu with a
1321 context menu, if this is relevant to the context.
1323 Context menu events contain a special accept flag that indicates
1324 whether the receiver accepted the event. If the event handler does
1325 not accept the event then, if possible, whatever triggered the event will be
1326 handled as a regular input event.
1329 #ifndef QT_NO_CONTEXTMENU
1331 Constructs a context menu event object with the accept parameter
1334 The \a reason parameter must be QContextMenuEvent::Mouse or
1335 QContextMenuEvent::Keyboard.
1337 The \a pos parameter specifies the mouse position relative to the
1338 receiving widget. \a globalPos is the mouse position in absolute
1341 QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
1342 : QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
1346 Constructs a context menu event object with the accept parameter
1349 The \a reason parameter must be QContextMenuEvent::Mouse or
1350 QContextMenuEvent::Keyboard.
1352 The \a pos parameter specifies the mouse position relative to the
1353 receiving widget. \a globalPos is the mouse position in absolute
1354 coordinates. The \a modifiers holds the keyboard modifiers.
1356 QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
1357 Qt::KeyboardModifiers modifiers)
1358 : QInputEvent(ContextMenu, modifiers), p(pos), gp(globalPos), reas(reason)
1363 QContextMenuEvent::~QContextMenuEvent()
1367 Constructs a context menu event object with the accept parameter
1370 The \a reason parameter must be QContextMenuEvent::Mouse or
1371 QContextMenuEvent::Keyboard.
1373 The \a pos parameter specifies the mouse position relative to the
1376 The globalPos() is initialized to QCursor::pos(), which may not be
1377 appropriate. Use the other constructor to specify the global
1378 position explicitly.
1380 QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
1381 : QInputEvent(ContextMenu), p(pos), reas(reason)
1383 gp = QCursor::pos();
1387 \fn const QPoint &QContextMenuEvent::pos() const
1389 Returns the position of the mouse pointer relative to the widget
1390 that received the event.
1392 \sa x(), y(), globalPos()
1396 \fn int QContextMenuEvent::x() const
1398 Returns the x position of the mouse pointer, relative to the
1399 widget that received the event.
1405 \fn int QContextMenuEvent::y() const
1407 Returns the y position of the mouse pointer, relative to the
1408 widget that received the event.
1414 \fn const QPoint &QContextMenuEvent::globalPos() const
1416 Returns the global position of the mouse pointer at the time of
1423 \fn int QContextMenuEvent::globalX() const
1425 Returns the global x position of the mouse pointer at the time of
1428 \sa globalY(), globalPos()
1432 \fn int QContextMenuEvent::globalY() const
1434 Returns the global y position of the mouse pointer at the time of
1437 \sa globalX(), globalPos()
1439 #endif // QT_NO_CONTEXTMENU
1442 \enum QContextMenuEvent::Reason
1444 This enum describes the reason why the event was sent.
1446 \value Mouse The mouse caused the event to be sent. Normally this
1447 means the right mouse button was clicked, but this is platform
1450 \value Keyboard The keyboard caused this event to be sent. On
1451 Windows, this means the menu button was pressed.
1453 \value Other The event was sent by some other means (i.e. not by
1454 the mouse or keyboard).
1459 \fn QContextMenuEvent::Reason QContextMenuEvent::reason() const
1461 Returns the reason for this context event.
1466 \class QInputMethodEvent
1467 \brief The QInputMethodEvent class provides parameters for input method events.
1471 Input method events are sent to widgets when an input method is
1472 used to enter text into a widget. Input methods are widely used
1473 to enter text for languages with non-Latin alphabets.
1475 Note that when creating custom text editing widgets, the
1476 Qt::WA_InputMethodEnabled window attribute must be set explicitly
1477 (using the QWidget::setAttribute() function) in order to receive
1478 input method events.
1480 The events are of interest to authors of keyboard entry widgets
1481 who want to be able to correctly handle languages with complex
1482 character input. Text input in such languages is usually a three
1486 \o \bold{Starting to Compose}
1488 When the user presses the first key on a keyboard, an input
1489 context is created. This input context will contain a string
1490 of the typed characters.
1494 With every new key pressed, the input method will try to create a
1495 matching string for the text typed so far called preedit
1496 string. While the input context is active, the user can only move
1497 the cursor inside the string belonging to this input context.
1499 \o \bold{Completing}
1501 At some point, the user will activate a user interface component
1502 (perhaps using a particular key) where they can choose from a
1503 number of strings matching the text they have typed so far. The
1504 user can either confirm their choice cancel the input; in either
1505 case the input context will be closed.
1508 QInputMethodEvent models these three stages, and transfers the
1509 information needed to correctly render the intermediate result. A
1510 QInputMethodEvent has two main parameters: preeditString() and
1511 commitString(). The preeditString() parameter gives the currently
1512 active preedit string. The commitString() parameter gives a text
1513 that should get added to (or replace parts of) the text of the
1514 editor widget. It usually is a result of the input operations and
1515 has to be inserted to the widgets text directly before the preedit
1518 If the commitString() should replace parts of the of the text in
1519 the editor, replacementLength() will contain the number of
1520 characters to be replaced. replacementStart() contains the position
1521 at which characters are to be replaced relative from the start of
1524 A number of attributes control the visual appearance of the
1525 preedit string (the visual appearance of text outside the preedit
1526 string is controlled by the widget only). The AttributeType enum
1527 describes the different attributes that can be set.
1529 A class implementing QWidget::inputMethodEvent() or
1530 QGraphicsItem::inputMethodEvent() should at least understand and
1531 honor the \l TextFormat and \l Cursor attributes.
1533 Since input methods need to be able to query certain properties
1534 from the widget or graphics item, subclasses must also implement
1535 QWidget::inputMethodQuery() and QGraphicsItem::inputMethodQuery(),
1538 When receiving an input method event, the text widget has to performs the
1542 \o If the widget has selected text, the selected text should get
1545 \o Remove the text starting at replacementStart() with length
1546 replacementLength() and replace it by the commitString(). If
1547 replacementLength() is 0, replacementStart() gives the insertion
1548 position for the commitString().
1550 When doing replacement the area of the preedit
1551 string is ignored, thus a replacement starting at -1 with a length
1552 of 2 will remove the last character before the preedit string and
1553 the first character afterwards, and insert the commit string
1554 directly before the preedit string.
1556 If the widget implements undo/redo, this operation gets added to
1559 \o If there is no current preedit string, insert the
1560 preeditString() at the current cursor position; otherwise replace
1561 the previous preeditString with the one received from this event.
1563 If the widget implements undo/redo, the preeditString() should not
1564 influence the undo/redo stack in any way.
1566 The widget should examine the list of attributes to apply to the
1567 preedit string. It has to understand at least the TextFormat and
1568 Cursor attributes and render them as specified.
1575 \enum QInputMethodEvent::AttributeType
1578 A QTextCharFormat for the part of the preedit string specified by
1579 start and length. value contains a QVariant of type QTextFormat
1580 specifying rendering of this part of the preedit string. There
1581 should be at most one format for every part of the preedit
1582 string. If several are specified for any character in the string the
1583 behaviour is undefined. A conforming implementation has to at least
1584 honor the backgroundColor, textColor and fontUnderline properties
1587 \value Cursor If set, a cursor should be shown inside the preedit
1588 string at position start. The length variable determines whether
1589 the cursor is visible or not. If the length is 0 the cursor is
1590 invisible. If value is a QVariant of type QColor this color will
1591 be used for rendering the cursor, otherwise the color of the
1592 surrounding text will be used. There should be at most one Cursor
1593 attribute per event. If several are specified the behaviour is
1597 The variant contains a QLocale object specifying the language of a
1598 certain part of the preedit string. There should be at most one
1599 language set for every part of the preedit string. If several are
1600 specified for any character in the string the behavior is undefined.
1603 The ruby text for a part of the preedit string. There should be at
1604 most one ruby text set for every part of the preedit string. If
1605 several are specified for any character in the string the behaviour
1609 If set, the edit cursor should be moved to the specified position
1610 in the editor text contents. In contrast with \c Cursor, this
1611 attribute does not work on the preedit text, but on the surrounding
1612 text. The cursor will be moved after the commit string has been
1613 committed, and the preedit string will be located at the new edit
1615 The start position specifies the new position and the length
1616 variable can be used to set a selection starting from that point.
1617 The value is unused.
1623 \class QInputMethodEvent::Attribute
1624 \brief The QInputMethodEvent::Attribute class stores an input method attribute.
1628 \fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length, QVariant value)
1630 Constructs an input method attribute. \a type specifies the type
1631 of attribute, \a start and \a length the position of the
1632 attribute, and \a value the value of the attribute.
1636 Constructs an event of type QEvent::InputMethod. The
1637 attributes(), preeditString(), commitString(), replacementStart(),
1638 and replacementLength() are initialized to default values.
1640 \sa setCommitString()
1642 QInputMethodEvent::QInputMethodEvent()
1643 : QEvent(QEvent::InputMethod), replace_from(0), replace_length(0)
1648 Construcs an event of type QEvent::InputMethod. The
1649 preedit text is set to \a preeditText, the attributes to
1652 The commitString(), replacementStart(), and replacementLength()
1653 values can be set using setCommitString().
1655 \sa preeditString(), attributes()
1657 QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes)
1658 : QEvent(QEvent::InputMethod), preedit(preeditText), attrs(attributes),
1659 replace_from(0), replace_length(0)
1664 Constructs a copy of \a other.
1666 QInputMethodEvent::QInputMethodEvent(const QInputMethodEvent &other)
1667 : QEvent(QEvent::InputMethod), preedit(other.preedit), attrs(other.attrs),
1668 commit(other.commit), replace_from(other.replace_from), replace_length(other.replace_length)
1673 Sets the commit string to \a commitString.
1675 The commit string is the text that should get added to (or
1676 replace parts of) the text of the editor widget. It usually is a
1677 result of the input operations and has to be inserted to the
1678 widgets text directly before the preedit string.
1680 If the commit string should replace parts of the of the text in
1681 the editor, \a replaceLength specifies the number of
1682 characters to be replaced. \a replaceFrom specifies the position
1683 at which characters are to be replaced relative from the start of
1686 \sa commitString(), replacementStart(), replacementLength()
1688 void QInputMethodEvent::setCommitString(const QString &commitString, int replaceFrom, int replaceLength)
1690 commit = commitString;
1691 replace_from = replaceFrom;
1692 replace_length = replaceLength;
1696 Sets the tentative commit string to \a tentativeCommitString.
1698 The tentative commit string is what the preedit string is expected to be committed as.
1699 The string can be used within the editor to trigger code that reacts on text changes such as validators.
1701 void QInputMethodEvent::setTentativeCommitString(const QString &tentativeCommitString)
1703 tentativeCommit = tentativeCommitString;
1707 \fn const QList<Attribute> &QInputMethodEvent::attributes() const
1709 Returns the list of attributes passed to the QInputMethodEvent
1710 constructor. The attributes control the visual appearance of the
1711 preedit string (the visual appearance of text outside the preedit
1712 string is controlled by the widget only).
1714 \sa preeditString(), Attribute
1718 \fn const QString &QInputMethodEvent::preeditString() const
1720 Returns the preedit text, i.e. the text before the user started
1723 \sa commitString(), attributes()
1727 \fn const QString &QInputMethodEvent::commitString() const
1729 Returns the text that should get added to (or replace parts of)
1730 the text of the editor widget. It usually is a result of the
1731 input operations and has to be inserted to the widgets text
1732 directly before the preedit string.
1734 \sa setCommitString(), preeditString(), replacementStart(), replacementLength()
1738 \fn int QInputMethodEvent::replacementStart() const
1740 Returns the position at which characters are to be replaced relative
1741 from the start of the preedit string.
1743 \sa replacementLength(), setCommitString()
1747 \fn int QInputMethodEvent::replacementLength() const
1749 Returns the number of characters to be replaced in the preedit
1752 \sa replacementStart(), setCommitString()
1756 \fn const QString &tentativeCommitString() const
1758 Returns the text as which preedit string is expected to be committed as.
1759 The string can be used within the editor to trigger code that reacts on text changes such as validators.
1761 \sa setTentativeCommitString()
1764 /*! \class QInputMethodQueryEvent
1766 This event is sent by the input context to input objects.
1769 input method to query a set of properties of the object to be
1770 able to support complex input method operations as support for
1771 surrounding text and reconversions.
1773 queries() specifies which properties are queried.
1775 The object should call setValue() on the event to fill in the requested
1776 data before calling accept().
1780 \fn Qt::InputMethodQueries QInputMethodQueryEvent::queries() const
1782 Returns the properties queried by the event.
1786 Constructs a query event for properties given by \a queries.
1788 QInputMethodQueryEvent::QInputMethodQueryEvent(Qt::InputMethodQueries queries)
1789 : QEvent(InputMethodQuery),
1797 QInputMethodQueryEvent::~QInputMethodQueryEvent()
1802 Sets query property to given value.
1804 void QInputMethodQueryEvent::setValue(Qt::InputMethodQuery query, const QVariant &value)
1806 for (int i = 0; i < m_values.size(); ++i) {
1807 if (m_values.at(i).query == query) {
1808 m_values[i].value = value;
1812 QueryPair pair = { query, value };
1813 m_values.append(pair);
1817 Returns value of a query property.
1819 QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const
1821 for (int i = 0; i < m_values.size(); ++i)
1822 if (m_values.at(i).query == query)
1823 return m_values.at(i).value;
1827 #ifndef QT_NO_TABLETEVENT
1831 \brief The QTabletEvent class contains parameters that describe a Tablet event.
1835 Tablet Events are generated from a Wacom tablet. Most of the time you will
1836 want to deal with events from the tablet as if they were events from a
1837 mouse; for example, you would retrieve the cursor position with x(), y(),
1838 pos(), globalX(), globalY(), and globalPos(). In some situations you may
1839 wish to retrieve the extra information provided by the tablet device
1840 driver; for example, you might want to do subpixeling with higher
1841 resolution coordinates or you may want to adjust color brightness based on
1842 pressure. QTabletEvent allows you to read the pressure(), the xTilt(), and
1843 yTilt(), as well as the type of device being used with device() (see
1844 \l{TabletDevice}). It can also give you the minimum and maximum values for
1845 each device's pressure and high resolution coordinates.
1847 A tablet event contains a special accept flag that indicates whether the
1848 receiver wants the event. You should call QTabletEvent::accept() if you
1849 handle the tablet event; otherwise it will be sent to the parent widget.
1850 The exception are TabletEnterProximity and TabletLeaveProximity events,
1851 these are only sent to QApplication and don't check whether or not they are
1854 The QWidget::setEnabled() function can be used to enable or
1855 disable mouse and keyboard events for a widget.
1857 The event handler QWidget::tabletEvent() receives all three types of
1858 tablet events. Qt will first send a tabletEvent then, if it is not
1859 accepted, it will send a mouse event. This allows applications that
1860 don't utilize tablets to use a tablet like a mouse, while also
1861 enabling those who want to use both tablets and mouses differently.
1863 \section1 Notes for X11 Users
1865 Qt uses the following hard-coded names to identify tablet
1866 devices from the xorg.conf file on X11 (apart from IRIX):
1867 'stylus', 'pen', and 'eraser'. If the devices have other names,
1868 they will not be picked up Qt.
1872 \enum QTabletEvent::TabletDevice
1874 This enum defines what type of device is generating the event.
1876 \value NoDevice No device, or an unknown device.
1877 \value Puck A Puck (a device that is similar to a flat mouse with
1878 a transparent circle with cross-hairs).
1879 \value Stylus A Stylus.
1880 \value Airbrush An airbrush
1881 \value FourDMouse A 4D Mouse.
1882 \value RotationStylus A special stylus that also knows about rotation
1883 (a 6D stylus). \since 4.1
1884 \omitvalue XFreeEraser
1888 \enum QTabletEvent::PointerType
1890 This enum defines what type of point is generating the event.
1892 \value UnknownPointer An unknown device.
1893 \value Pen Tip end of a stylus-like device (the narrow end of the pen).
1894 \value Cursor Any puck-like device.
1895 \value Eraser Eraser end of a stylus-like device (the broad end of the pen).
1901 Construct a tablet event of the given \a type.
1903 The \a pos parameter indicates where the event occurred in the
1904 widget; \a globalPos is the corresponding position in absolute
1905 coordinates. The \a hiResGlobalPos contains a high resolution
1906 measurement of the position.
1908 \a pressure contains the pressure exerted on the \a device.
1910 \a pointerType describes the type of pen that is being used.
1912 \a xTilt and \a yTilt contain the device's degree of tilt from the
1913 x and y axes respectively.
1915 \a keyState specifies which keyboard modifiers are pressed (e.g.,
1918 The \a uniqueID parameter contains the unique ID for the current device.
1920 The \a z parameter contains the coordinate of the device on the tablet, this
1921 is usually given by a wheel on 4D mouse. If the device does not support a
1922 Z-axis, pass zero here.
1924 The \a tangentialPressure parameter contins the tangential pressure of an air
1925 brush. If the device does not support tangential pressure, pass 0 here.
1927 \a rotation contains the device's rotation in degrees. 4D mice support
1928 rotation. If the device does not support rotation, pass 0 here.
1930 \sa pos() globalPos() device() pressure() xTilt() yTilt() uniqueId(), rotation(), tangentialPressure(), z()
1933 QTabletEvent::QTabletEvent(Type type, const QPointF &pos, const QPointF &globalPos,
1934 int device, int pointerType,
1935 qreal pressure, int xTilt, int yTilt, qreal tangentialPressure,
1936 qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID)
1937 : QInputEvent(type, keyState),
1941 mPointerType(pointerType),
1946 mTangential(tangentialPressure),
1956 QTabletEvent::~QTabletEvent()
1961 \fn TabletDevices QTabletEvent::device() const
1963 Returns the type of device that generated the event.
1969 \fn PointerType QTabletEvent::pointerType() const
1971 Returns the type of point that generated the event.
1975 \fn qreal QTabletEvent::tangentialPressure() const
1977 Returns the tangential pressure for the device. This is typically given by a finger
1978 wheel on an airbrush tool. The range is from -1.0 to 1.0. 0.0 indicates a
1979 neutral position. Current airbrushes can only move in the positive
1980 direction from the neutrual position. If the device does not support
1981 tangential pressure, this value is always 0.0.
1987 \fn qreal QTabletEvent::rotation() const
1989 Returns the rotation of the current device in degress. This is usually
1990 given by a 4D Mouse. If the device doesn't support rotation this value is
1996 \fn qreal QTabletEvent::pressure() const
1998 Returns the pressure for the device. 0.0 indicates that the stylus is not
1999 on the tablet, 1.0 indicates the maximum amount of pressure for the stylus.
2001 \sa tangentialPressure()
2005 \fn int QTabletEvent::xTilt() const
2007 Returns the angle between the device (a pen, for example) and the
2008 perpendicular in the direction of the x axis.
2009 Positive values are towards the tablet's physical right. The angle
2010 is in the range -60 to +60 degrees.
2012 \img qtabletevent-tilt.png
2018 \fn int QTabletEvent::yTilt() const
2020 Returns the angle between the device (a pen, for example) and the
2021 perpendicular in the direction of the y axis.
2022 Positive values are towards the bottom of the tablet. The angle is
2023 within the range -60 to +60 degrees.
2029 \fn const QPoint &QTabletEvent::pos() const
2031 Returns the position of the device, relative to the widget that
2034 If you move widgets around in response to mouse events, use
2035 globalPos() instead of this function.
2037 \sa x() y() globalPos()
2041 \fn int QTabletEvent::x() const
2043 Returns the x position of the device, relative to the widget that
2050 \fn int QTabletEvent::y() const
2052 Returns the y position of the device, relative to the widget that
2059 \fn int QTabletEvent::z() const
2061 Returns the z position of the device. Typically this is represented by a
2062 wheel on a 4D Mouse. If the device does not support a Z-axis, this value is
2063 always zero. This is \bold not the same as pressure.
2069 \fn const QPoint &QTabletEvent::globalPos() const
2071 Returns the global position of the device \e{at the time of the
2072 event}. This is important on asynchronous windows systems like X11;
2073 whenever you move your widgets around in response to mouse events,
2074 globalPos() can differ significantly from the current position
2077 \sa globalX() globalY() hiResGlobalPos()
2081 \fn int QTabletEvent::globalX() const
2083 Returns the global x position of the mouse pointer at the time of
2086 \sa globalY() globalPos() hiResGlobalX()
2090 \fn int QTabletEvent::globalY() const
2092 Returns the global y position of the tablet device at the time of
2095 \sa globalX() globalPos() hiResGlobalY()
2099 \fn qint64 QTabletEvent::uniqueId() const
2101 Returns a unique ID for the current device, making it possible
2102 to differentiate between multiple devices being used at the same
2105 Support of this feature is dependent on the tablet.
2107 Values for the same device may vary from OS to OS.
2109 Later versions of the Wacom driver for Linux will now report
2110 the ID information. If you have a tablet that supports unique ID
2111 and are not getting the information on Linux, consider upgrading
2114 As of Qt 4.2, the unique ID is the same regardless of the orientation
2115 of the pen. Earlier versions would report a different value when using
2116 the eraser-end versus the pen-end of the stylus on some OS's.
2122 \fn const QPointF &QTabletEvent::hiResGlobalPos() const
2124 The high precision coordinates delivered from the tablet expressed.
2125 Sub pixeling information is in the fractional part of the QPointF.
2127 \sa globalPos() hiResGlobalX() hiResGlobalY()
2131 \fn qreal &QTabletEvent::hiResGlobalX() const
2133 The high precision x position of the tablet device.
2137 \fn qreal &QTabletEvent::hiResGlobalY() const
2139 The high precision y position of the tablet device.
2142 #endif // QT_NO_TABLETEVENT
2144 #ifndef QT_NO_DRAGANDDROP
2146 Creates a QDragMoveEvent of the required \a type indicating
2147 that the mouse is at position \a pos given within a widget.
2149 The mouse and keyboard states are specified by \a buttons and
2150 \a modifiers, and the \a actions describe the types of drag
2151 and drop operation that are possible.
2152 The drag data is passed as MIME-encoded information in \a data.
2154 \warning Do not attempt to create a QDragMoveEvent yourself.
2155 These objects rely on Qt's internal state.
2157 QDragMoveEvent::QDragMoveEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
2158 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
2159 : QDropEvent(pos, actions, data, buttons, modifiers, type)
2160 , rect(pos, QSize(1, 1))
2166 QDragMoveEvent::~QDragMoveEvent()
2171 \fn void QDragMoveEvent::accept(const QRect &rectangle)
2173 The same as accept(), but also notifies that future moves will
2174 also be acceptable if they remain within the \a rectangle
2175 given on the widget. This can improve performance, but may
2176 also be ignored by the underlying system.
2178 If the rectangle is empty, drag move events will be sent
2179 continuously. This is useful if the source is scrolling in a
2184 \fn void QDragMoveEvent::accept()
2188 Calls QDropEvent::accept().
2192 \fn void QDragMoveEvent::ignore()
2196 Calls QDropEvent::ignore().
2200 \fn void QDragMoveEvent::ignore(const QRect &rectangle)
2202 The opposite of the accept(const QRect&) function.
2203 Moves within the \a rectangle are not acceptable, and will be
2208 \fn QRect QDragMoveEvent::answerRect() const
2210 Returns the rectangle in the widget where the drop will occur if accepted.
2211 You can use this information to restrict drops to certain places on the
2219 \ingroup draganddrop
2221 \brief The QDropEvent class provides an event which is sent when a
2222 drag and drop action is completed.
2224 When a widget \l{QWidget::setAcceptDrops()}{accepts drop events}, it will
2225 receive this event if it has accepted the most recent QDragEnterEvent or
2226 QDragMoveEvent sent to it.
2228 The drop event contains a proposed action, available from proposedAction(), for
2229 the widget to either accept or ignore. If the action can be handled by the
2230 widget, you should call the acceptProposedAction() function. Since the
2231 proposed action can be a combination of \l Qt::DropAction values, it may be
2232 useful to either select one of these values as a default action or ask
2233 the user to select their preferred action.
2235 If the proposed drop action is not suitable, perhaps because your custom
2236 widget does not support that action, you can replace it with any of the
2237 \l{possibleActions()}{possible drop actions} by calling setDropAction()
2238 with your preferred action. If you set a value that is not present in the
2239 bitwise OR combination of values returned by possibleActions(), the default
2240 copy action will be used. Once a replacement drop action has been set, call
2241 accept() instead of acceptProposedAction() to complete the drop operation.
2243 The mimeData() function provides the data dropped on the widget in a QMimeData
2244 object. This contains information about the MIME type of the data in addition to
2247 \sa QMimeData, QDrag, {Drag and Drop}
2251 \fn const QMimeData *QDropEvent::mimeData() const
2253 Returns the data that was dropped on the widget and its associated MIME
2258 Constructs a drop event of a certain \a type corresponding to a
2259 drop at the point specified by \a pos in the destination widget's
2262 The \a actions indicate which types of drag and drop operation can
2263 be performed, and the drag data is stored as MIME-encoded data in \a data.
2265 The states of the mouse buttons and keyboard modifiers at the time of
2266 the drop are specified by \a buttons and \a modifiers.
2267 */ // ### pos is in which coordinate system?
2268 QDropEvent::QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
2269 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
2270 : QEvent(type), p(pos), mouseState(buttons),
2271 modState(modifiers), act(actions),
2274 default_action = Qt::CopyAction; // ### Qt5: QDragManager::self()->defaultAction(act, modifiers);
2275 drop_action = default_action;
2280 QDropEvent::~QDropEvent()
2286 If the source of the drag operation is a widget in this
2287 application, this function returns that source; otherwise it
2288 returns 0. The source of the operation is the first parameter to
2289 the QDrag object used instantiate the drag.
2291 This is useful if your widget needs special behavior when dragging
2296 QObject* QDropEvent::source() const
2298 if (const QDragManager *manager = QDragManager::self())
2299 return manager->source();
2304 void QDropEvent::setDropAction(Qt::DropAction action)
2306 if (!(action & act) && action != Qt::IgnoreAction)
2307 action = default_action;
2308 drop_action = action;
2312 \fn const QPoint& QDropEvent::pos() const
2314 Returns the position where the drop was made.
2318 \fn Qt::MouseButtons QDropEvent::mouseButtons() const
2320 Returns the mouse buttons that are pressed..
2324 \fn Qt::KeyboardModifiers QDropEvent::keyboardModifiers() const
2326 Returns the modifier keys that are pressed.
2330 \fn void QDropEvent::setDropAction(Qt::DropAction action)
2332 Sets the \a action to be performed on the data by the target.
2333 Use this to override the \l{proposedAction()}{proposed action}
2334 with one of the \l{possibleActions()}{possible actions}.
2336 If you set a drop action that is not one of the possible actions, the
2337 drag and drop operation will default to a copy operation.
2339 Once you have supplied a replacement drop action, call accept()
2340 instead of acceptProposedAction().
2346 \fn Qt::DropAction QDropEvent::dropAction() const
2348 Returns the action to be performed on the data by the target. This may be
2349 different from the action supplied in proposedAction() if you have called
2350 setDropAction() to explicitly choose a drop action.
2356 \fn Qt::DropActions QDropEvent::possibleActions() const
2358 Returns an OR-combination of possible drop actions.
2364 \fn Qt::DropAction QDropEvent::proposedAction() const
2366 Returns the proposed drop action.
2372 \fn void QDropEvent::acceptProposedAction()
2374 Sets the drop action to be the proposed action.
2376 \sa setDropAction(), proposedAction(), {QEvent::accept()}{accept()}
2380 \class QDragEnterEvent
2381 \brief The QDragEnterEvent class provides an event which is sent
2382 to a widget when a drag and drop action enters it.
2385 \ingroup draganddrop
2387 A widget must accept this event in order to receive the \l
2388 {QDragMoveEvent}{drag move events} that are sent while the drag
2389 and drop action is in progress. The drag enter event is always
2390 immediately followed by a drag move event.
2392 QDragEnterEvent inherits most of its functionality from
2393 QDragMoveEvent, which in turn inherits most of its functionality
2396 \sa QDragLeaveEvent, QDragMoveEvent, QDropEvent
2400 Constructs a QDragEnterEvent that represents a drag entering a
2401 widget at the given \a point with mouse and keyboard states specified by
2402 \a buttons and \a modifiers.
2404 The drag data is passed as MIME-encoded information in \a data, and the
2405 specified \a actions describe the possible types of drag and drop
2406 operation that can be performed.
2408 \warning Do not create a QDragEnterEvent yourself since these
2409 objects rely on Qt's internal state.
2411 QDragEnterEvent::QDragEnterEvent(const QPoint& point, Qt::DropActions actions, const QMimeData *data,
2412 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
2413 : QDragMoveEvent(point, actions, data, buttons, modifiers, DragEnter)
2418 QDragEnterEvent::~QDragEnterEvent()
2423 \class QDragMoveEvent
2424 \brief The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress.
2427 \ingroup draganddrop
2429 A widget will receive drag move events repeatedly while the drag
2430 is within its boundaries, if it accepts
2431 \l{QWidget::setAcceptDrops()}{drop events} and \l
2432 {QWidget::dragEnterEvent()}{enter events}. The widget should
2433 examine the event to see what kind of data it
2434 \l{QDragMoveEvent::provides()}{provides}, and call the accept()
2435 function to accept the drop if appropriate.
2437 The rectangle supplied by the answerRect() function can be used to restrict
2438 drops to certain parts of the widget. For example, we can check whether the
2439 rectangle intersects with the geometry of a certain child widget and only
2440 call \l{QDropEvent::acceptProposedAction()}{acceptProposedAction()} if that
2443 Note that this class inherits most of its functionality from
2446 \sa QDragEnterEvent, QDragLeaveEvent, QDropEvent
2450 \class QDragLeaveEvent
2451 \brief The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leaves it.
2454 \ingroup draganddrop
2456 This event is always preceded by a QDragEnterEvent and a series
2457 of \l{QDragMoveEvent}s. It is not sent if a QDropEvent is sent
2460 \sa QDragEnterEvent, QDragMoveEvent, QDropEvent
2464 Constructs a QDragLeaveEvent.
2466 \warning Do not create a QDragLeaveEvent yourself since these
2467 objects rely on Qt's internal state.
2469 QDragLeaveEvent::QDragLeaveEvent()
2475 QDragLeaveEvent::~QDragLeaveEvent()
2478 #endif // QT_NO_DRAGANDDROP
2482 \brief The QHelpEvent class provides an event that is used to request helpful information
2483 about a particular point in a widget.
2488 This event can be intercepted in applications to provide tooltips
2489 or "What's This?" help for custom widgets. The type() can be
2490 either QEvent::ToolTip or QEvent::WhatsThis.
2492 \sa QToolTip, QWhatsThis, QStatusTipEvent, QWhatsThisClickedEvent
2496 Constructs a help event with the given \a type corresponding to the
2497 widget-relative position specified by \a pos and the global position
2498 specified by \a globalPos.
2500 \a type must be either QEvent::ToolTip or QEvent::WhatsThis.
2502 \sa pos(), globalPos()
2504 QHelpEvent::QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos)
2505 : QEvent(type), p(pos), gp(globalPos)
2509 \fn int QHelpEvent::x() const
2513 \sa y(), pos(), globalPos()
2517 \fn int QHelpEvent::y() const
2521 \sa x(), pos(), globalPos()
2525 \fn int QHelpEvent::globalX() const
2527 Same as globalPos().x().
2529 \sa x(), globalY(), globalPos()
2533 \fn int QHelpEvent::globalY() const
2535 Same as globalPos().y().
2537 \sa y(), globalX(), globalPos()
2541 \fn const QPoint &QHelpEvent::pos() const
2543 Returns the mouse cursor position when the event was generated,
2544 relative to the widget to which the event is dispatched.
2546 \sa globalPos(), x(), y()
2550 \fn const QPoint &QHelpEvent::globalPos() const
2552 Returns the mouse cursor position when the event was generated
2553 in global coordinates.
2555 \sa pos(), globalX(), globalY()
2560 QHelpEvent::~QHelpEvent()
2564 #ifndef QT_NO_STATUSTIP
2567 \class QStatusTipEvent
2568 \brief The QStatusTipEvent class provides an event that is used to show messages in a status bar.
2573 Status tips can be set on a widget using the
2574 QWidget::setStatusTip() function. They are shown in the status
2575 bar when the mouse cursor enters the widget. For example:
2580 \snippet doc/src/snippets/qstatustipevent/main.cpp 1
2582 \snippet doc/src/snippets/qstatustipevent/main.cpp 3
2584 \image qstatustipevent-widget.png Widget with status tip.
2587 Status tips can also be set on actions using the
2588 QAction::setStatusTip() function:
2593 \snippet doc/src/snippets/qstatustipevent/main.cpp 0
2594 \snippet doc/src/snippets/qstatustipevent/main.cpp 2
2596 \snippet doc/src/snippets/qstatustipevent/main.cpp 3
2598 \image qstatustipevent-action.png Action with status tip.
2601 Finally, status tips are supported for the item view classes
2602 through the Qt::StatusTipRole enum value.
2604 \sa QStatusBar, QHelpEvent, QWhatsThisClickedEvent
2608 Constructs a status tip event with the text specified by \a tip.
2612 QStatusTipEvent::QStatusTipEvent(const QString &tip)
2613 : QEvent(StatusTip), s(tip)
2618 QStatusTipEvent::~QStatusTipEvent()
2623 \fn QString QStatusTipEvent::tip() const
2625 Returns the message to show in the status bar.
2627 \sa QStatusBar::showMessage()
2630 #endif // QT_NO_STATUSTIP
2632 #ifndef QT_NO_WHATSTHIS
2635 \class QWhatsThisClickedEvent
2636 \brief The QWhatsThisClickedEvent class provides an event that
2637 can be used to handle hyperlinks in a "What's This?" text.
2642 \sa QWhatsThis, QHelpEvent, QStatusTipEvent
2646 Constructs an event containing a URL specified by \a href when a link
2647 is clicked in a "What's This?" message.
2651 QWhatsThisClickedEvent::QWhatsThisClickedEvent(const QString &href)
2652 : QEvent(WhatsThisClicked), s(href)
2657 QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
2662 \fn QString QWhatsThisClickedEvent::href() const
2664 Returns the URL that was clicked by the user in the "What's
2668 #endif // QT_NO_WHATSTHIS
2670 #ifndef QT_NO_ACTION
2674 \brief The QActionEvent class provides an event that is generated
2675 when a QAction is added, removed, or changed.
2679 Actions can be added to widgets using QWidget::addAction(). This
2680 generates an \l ActionAdded event, which you can handle to provide
2681 custom behavior. For example, QToolBar reimplements
2682 QWidget::actionEvent() to create \l{QToolButton}s for the
2685 \sa QAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions()
2689 Constructs an action event. The \a type can be \l ActionChanged,
2690 \l ActionAdded, or \l ActionRemoved.
2692 \a action is the action that is changed, added, or removed. If \a
2693 type is ActionAdded, the action is to be inserted before the
2694 action \a before. If \a before is 0, the action is appended.
2696 QActionEvent::QActionEvent(int type, QAction *action, QAction *before)
2697 : QEvent(static_cast<QEvent::Type>(type)), act(action), bef(before)
2702 QActionEvent::~QActionEvent()
2707 \fn QAction *QActionEvent::action() const
2709 Returns the action that is changed, added, or removed.
2715 \fn QAction *QActionEvent::before() const
2717 If type() is \l ActionAdded, returns the action that should
2718 appear before action(). If this function returns 0, the action
2719 should be appended to already existing actions on the same
2722 \sa action(), QWidget::actions()
2725 #endif // QT_NO_ACTION
2729 \brief The QHideEvent class provides an event which is sent after a widget is hidden.
2733 This event is sent just before QWidget::hide() returns, and also
2734 when a top-level window has been hidden (iconified) by the user.
2736 If spontaneous() is true, the event originated outside the
2737 application. In this case, the user hid the window using the
2738 window manager controls, either by iconifying the window or by
2739 switching to another virtual desktop where the window isn't
2740 visible. The window will become hidden but not withdrawn. If the
2741 window was iconified, QWidget::isMinimized() returns true.
2747 Constructs a QHideEvent.
2749 QHideEvent::QHideEvent()
2755 QHideEvent::~QHideEvent()
2761 \brief The QShowEvent class provides an event that is sent when a widget is shown.
2765 There are two kinds of show events: show events caused by the
2766 window system (spontaneous), and internal show events. Spontaneous (QEvent::spontaneous())
2767 show events are sent just after the window system shows the
2768 window; they are also sent when a top-level window is redisplayed
2769 after being iconified. Internal show events are delivered just
2770 before the widget becomes visible.
2776 Constructs a QShowEvent.
2778 QShowEvent::QShowEvent()
2784 QShowEvent::~QShowEvent()
2789 \class QFileOpenEvent
2790 \brief The QFileOpenEvent class provides an event that will be
2791 sent when there is a request to open a file or a URL.
2795 File open events will be sent to the QApplication::instance()
2796 when the operating system requests that a file or URL should be opened.
2797 This is a high-level event that can be caused by different user actions
2798 depending on the user's desktop environment; for example, double
2799 clicking on an file icon in the Finder on Mac OS X.
2801 This event is only used to notify the application of a request.
2802 It may be safely ignored.
2804 \note This class is currently supported for Mac OS X only.
2807 QFileOpenEventPrivate::~QFileOpenEventPrivate()
2814 Constructs a file open event for the given \a file.
2816 QFileOpenEvent::QFileOpenEvent(const QString &file)
2817 : QEvent(FileOpen), f(file)
2819 d = reinterpret_cast<QEventPrivate *>(new QFileOpenEventPrivate(QUrl::fromLocalFile(file)));
2825 Constructs a file open event for the given \a url.
2827 QFileOpenEvent::QFileOpenEvent(const QUrl &url)
2830 d = reinterpret_cast<QEventPrivate *>(new QFileOpenEventPrivate(url));
2831 f = url.toLocalFile();
2837 QFileOpenEvent::~QFileOpenEvent()
2839 delete reinterpret_cast<QFileOpenEventPrivate *>(d);
2843 \fn QString QFileOpenEvent::file() const
2845 Returns the file that is being opened.
2849 \fn QUrl QFileOpenEvent::url() const
2851 Returns the url that is being opened.
2855 QUrl QFileOpenEvent::url() const
2857 return reinterpret_cast<const QFileOpenEventPrivate *>(d)->url;
2861 \fn bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
2863 Opens a QFile on the \a file referenced by this event in the mode specified
2864 by \a flags. Returns true if successful; otherwise returns false.
2866 This is necessary as some files cannot be opened by name, but require specific
2867 information stored in this event.
2871 bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
2873 file.setFileName(f);
2874 return file.open(flags);
2877 #ifndef QT_NO_TOOLBAR
2880 \class QToolBarChangeEvent
2881 \brief The QToolBarChangeEvent class provides an event that is
2882 sent whenever a the toolbar button is clicked on Mac OS X.
2886 The QToolBarChangeEvent is sent when the toolbar button is clicked. On Mac
2887 OS X, this is the long oblong button on the right side of the window
2888 title bar. The default implementation is to toggle the appearance (hidden or
2889 shown) of the associated toolbars for the window.
2895 Construct a QToolBarChangeEvent given the current button state in \a state.
2897 QToolBarChangeEvent::QToolBarChangeEvent(bool t)
2898 : QEvent(ToolBarChange), tog(t)
2903 QToolBarChangeEvent::~QToolBarChangeEvent()
2908 \fn bool QToolBarChangeEvent::toggle() const
2913 \fn Qt::ButtonState QToolBarChangeEvent::state() const
2915 Returns the keyboard modifier flags at the time of the event.
2917 The returned value is a selection of the following values,
2918 combined using the OR operator:
2919 Qt::ShiftButton, Qt::ControlButton, Qt::MetaButton, and Qt::AltButton.
2922 #endif // QT_NO_TOOLBAR
2924 #ifndef QT_NO_SHORTCUT
2927 Constructs a shortcut event for the given \a key press,
2928 associated with the QShortcut ID \a id.
2930 \a ambiguous specifies whether there is more than one QShortcut
2931 for the same key sequence.
2933 QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous)
2934 : QEvent(Shortcut), sequence(key), ambig(ambiguous), sid(id)
2939 Destroys the event object.
2941 QShortcutEvent::~QShortcutEvent()
2945 #endif // QT_NO_SHORTCUT
2947 #ifndef QT_NO_DEBUG_STREAM
2948 QDebug operator<<(QDebug dbg, const QEvent *e) {
2949 // More useful event output could be added here
2951 return dbg << "QEvent(this = 0x0)";
2953 switch (e->type()) {
2957 case QEvent::MouseButtonPress:
2958 case QEvent::MouseMove:
2959 case QEvent::MouseButtonRelease:
2960 case QEvent::MouseButtonDblClick:
2962 const QMouseEvent *me = static_cast<const QMouseEvent*>(e);
2963 switch(me->type()) {
2964 case QEvent::MouseButtonPress:
2965 n = "MouseButtonPress";
2967 case QEvent::MouseMove:
2970 case QEvent::MouseButtonRelease:
2971 n = "MouseButtonRelease";
2973 case QEvent::MouseButtonDblClick:
2975 n = "MouseButtonDblClick";
2978 dbg.nospace() << "QMouseEvent(" << n
2979 << ", " << me->button()
2980 << ", " << hex << (int)me->buttons()
2981 << ", " << hex << (int)me->modifiers()
2986 #ifndef QT_NO_TOOLTIP
2987 case QEvent::ToolTip:
2991 case QEvent::WindowActivate:
2992 n = "WindowActivate";
2994 case QEvent::WindowDeactivate:
2995 n = "WindowDeactivate";
2997 case QEvent::ActivationChange:
2998 n = "ActivationChange";
3000 #ifndef QT_NO_WHEELEVENT
3002 dbg.nospace() << "QWheelEvent("
3003 << static_cast<const QWheelEvent *>(e)->pixelDelta()
3004 << static_cast<const QWheelEvent *>(e)->angleDelta()
3008 case QEvent::KeyPress:
3009 case QEvent::KeyRelease:
3010 case QEvent::ShortcutOverride:
3012 const QKeyEvent *ke = static_cast<const QKeyEvent*>(e);
3013 switch(ke->type()) {
3014 case QEvent::ShortcutOverride:
3015 n = "ShortcutOverride";
3017 case QEvent::KeyRelease:
3020 case QEvent::KeyPress:
3025 dbg.nospace() << "QKeyEvent(" << n
3026 << ", " << hex << ke->key()
3027 << ", " << hex << (int)ke->modifiers()
3028 << ", \"" << ke->text()
3029 << "\", " << ke->isAutoRepeat()
3030 << ", " << ke->count()
3034 case QEvent::FocusIn:
3037 case QEvent::FocusOut:
3046 case QEvent::PaletteChange:
3047 n = "PaletteChange";
3049 case QEvent::PolishRequest:
3050 n = "PolishRequest";
3052 case QEvent::Polish:
3055 case QEvent::UpdateRequest:
3056 n = "UpdateRequest";
3064 case QEvent::Resize:
3067 case QEvent::Create:
3070 case QEvent::Destroy:
3079 case QEvent::FileOpen:
3085 case QEvent::ShowToParent:
3091 case QEvent::HideToParent:
3097 case QEvent::ParentChange:
3100 case QEvent::ParentAboutToChange:
3101 n = "ParentAboutToChange";
3103 case QEvent::HoverEnter:
3106 case QEvent::HoverMove:
3109 case QEvent::HoverLeave:
3112 case QEvent::ZOrderChange:
3115 case QEvent::StyleChange:
3118 case QEvent::DragEnter:
3121 case QEvent::DragMove:
3124 case QEvent::DragLeave:
3130 case QEvent::GraphicsSceneMouseMove:
3131 n = "GraphicsSceneMouseMove";
3133 case QEvent::GraphicsSceneMousePress:
3134 n = "GraphicsSceneMousePress";
3136 case QEvent::GraphicsSceneMouseRelease:
3137 n = "GraphicsSceneMouseRelease";
3139 case QEvent::GraphicsSceneMouseDoubleClick:
3140 n = "GraphicsSceneMouseDoubleClick";
3142 case QEvent::GraphicsSceneContextMenu:
3143 n = "GraphicsSceneContextMenu";
3145 case QEvent::GraphicsSceneHoverEnter:
3146 n = "GraphicsSceneHoverEnter";
3148 case QEvent::GraphicsSceneHoverMove:
3149 n = "GraphicsSceneHoverMove";
3151 case QEvent::GraphicsSceneHoverLeave:
3152 n = "GraphicsSceneHoverLeave";
3154 case QEvent::GraphicsSceneHelp:
3155 n = "GraphicsSceneHelp";
3157 case QEvent::GraphicsSceneDragEnter:
3158 n = "GraphicsSceneDragEnter";
3160 case QEvent::GraphicsSceneDragMove:
3161 n = "GraphicsSceneDragMove";
3163 case QEvent::GraphicsSceneDragLeave:
3164 n = "GraphicsSceneDragLeave";
3166 case QEvent::GraphicsSceneDrop:
3167 n = "GraphicsSceneDrop";
3169 case QEvent::GraphicsSceneWheel:
3170 n = "GraphicsSceneWheel";
3172 case QEvent::GraphicsSceneResize:
3173 n = "GraphicsSceneResize";
3175 case QEvent::GraphicsSceneMove:
3176 n = "GraphicsSceneMove";
3178 case QEvent::CursorChange:
3181 case QEvent::ToolTipChange:
3182 n = "ToolTipChange";
3184 case QEvent::StatusTip:
3187 case QEvent::WhatsThis:
3190 case QEvent::FontChange:
3196 case QEvent::KeyboardLayoutChange:
3197 n = "KeyboardLayoutChange";
3199 case QEvent::DynamicPropertyChange:
3200 n = "DynamicPropertyChange";
3202 case QEvent::GrabMouse:
3205 case QEvent::UngrabMouse:
3208 case QEvent::GrabKeyboard:
3211 case QEvent::UngrabKeyboard:
3212 n = "UngrabKeyboard";
3214 case QEvent::ChildAdded: n = n ? n : "ChildAdded";
3215 case QEvent::ChildPolished: n = n ? n : "ChildPolished";
3216 case QEvent::ChildRemoved: n = n ? n : "ChildRemoved";
3217 dbg.nospace() << "QChildEvent(" << n << ", " << (static_cast<const QChildEvent*>(e))->child();
3219 #ifndef QT_NO_GESTURES
3220 case QEvent::Gesture:
3225 dbg.nospace() << "QEvent(" << (const void *)e << ", type = " << e->type() << ')';
3229 dbg.nospace() << 'Q' << n << "Event(" << (const void *)e << ')';
3234 #ifndef QT_NO_CLIPBOARD
3236 \class QClipboardEvent
3240 \brief The QClipboardEvent class provides the parameters used in a clipboard event.
3242 This class is for internal use only, and exists to aid the clipboard on various
3243 platforms to get all the information it needs. Use QEvent::Clipboard instead.
3248 QClipboardEvent::QClipboardEvent(QEventPrivate *data)
3249 : QEvent(QEvent::Clipboard)
3254 QClipboardEvent::~QClipboardEvent()
3257 #endif // QT_NO_CLIPBOARD
3260 \class QShortcutEvent
3261 \brief The QShortcutEvent class provides an event which is generated when
3262 the user presses a key combination.
3266 Normally you don't need to use this class directly; QShortcut
3267 provides a higher-level interface to handle shortcut keys.
3273 \fn const QKeySequence &QShortcutEvent::key() const
3275 Returns the key sequence that triggered the event.
3279 \fn int QShortcutEvent::shortcutId() const
3281 Returns the ID of the QShortcut object for which this event was
3288 \fn bool QShortcutEvent::isAmbiguous() const
3290 Returns true if the key sequence that triggered the event is
3293 \sa QShortcut::activatedAmbiguously()
3297 \class QWindowStateChangeEvent
3300 \brief The QWindowStateChangeEvent class provides the window state before a
3301 window state change.
3304 /*! \fn Qt::WindowStates QWindowStateChangeEvent::oldState() const
3306 Returns the state of the window before the change.
3311 QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s)
3312 : QEvent(WindowStateChange), ostate(s)
3318 QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s, bool isOverride)
3319 : QEvent(WindowStateChange), ostate(s)
3322 d = (QEventPrivate*)(this);
3327 bool QWindowStateChangeEvent::isOverride() const
3334 QWindowStateChangeEvent::~QWindowStateChangeEvent()
3341 \brief The QTouchEvent class contains parameters that describe a touch event.
3346 \section1 Enabling Touch Events
3348 Touch events occur when pressing, releasing, or moving one or more touch points on a touch
3349 device (such as a touch-screen or track-pad). To receive touch events, widgets have to have the
3350 Qt::WA_AcceptTouchEvents attribute set and graphics items need to have the
3351 \l{QGraphicsItem::setAcceptTouchEvents()}{acceptTouchEvents} attribute set to true.
3353 When using QAbstractScrollArea based widgets, you should enable the Qt::WA_AcceptTouchEvents
3354 attribute on the scroll area's \l{QAbstractScrollArea::viewport()}{viewport}.
3356 Similarly to QMouseEvent, Qt automatically grabs each touch point on the first press inside a
3357 widget, and the widget will receive all updates for the touch point until it is released.
3358 Note that it is possible for a widget to receive events for numerous touch points, and that
3359 multiple widgets may be receiving touch events at the same time.
3361 \section1 Event Handling
3363 All touch events are of type QEvent::TouchBegin, QEvent::TouchUpdate, QEvent::TouchEnd or
3364 QEvent::TouchCancel. Reimplement QWidget::event() or QAbstractScrollArea::viewportEvent() for
3365 widgets and QGraphicsItem::sceneEvent() for items in a graphics view to receive touch events.
3367 The QEvent::TouchUpdate and QEvent::TouchEnd events are sent to the widget or item that
3368 accepted the QEvent::TouchBegin event. If the QEvent::TouchBegin event is not accepted and not
3369 filtered by an event filter, then no further touch events are sent until the next
3372 Some systems may send an event of type QEvent::TouchCancel. Upon receiving this event
3373 applications are requested to ignore the entire active touch sequence. For example in a
3374 composited system the compositor may decide to treat certain gestures as system-wide
3375 gestures. Whenever such a decision is made (the gesture is recognized), the clients will be
3376 notified with a QEvent::TouchCancel event so they can update their state accordingly.
3378 The touchPoints() function returns a list of all touch points contained in the event.
3379 Information about each touch point can be retrieved using the QTouchEvent::TouchPoint class.
3380 The Qt::TouchPointState enum describes the different states that a touch point may have.
3382 \section1 Event Delivery and Propagation
3384 By default, QGuiApplication translates the first touch point in a QTouchEvent into
3385 a QMouseEvent. This makes it possible to enable touch events on existing widgets that do not
3386 normally handle QTouchEvent. See below for information on some special considerations needed
3389 QEvent::TouchBegin is the first touch event sent to a widget. The QEvent::TouchBegin event
3390 contains a special accept flag that indicates whether the receiver wants the event. By default,
3391 the event is accepted. You should call ignore() if the touch event is not handled by your
3392 widget. The QEvent::TouchBegin event is propagated up the parent widget chain until a widget
3393 accepts it with accept(), or an event filter consumes it. For QGraphicsItems, the
3394 QEvent::TouchBegin event is propagated to items under the mouse (similar to mouse event
3395 propagation for QGraphicsItems).
3397 \section1 Touch Point Grouping
3399 As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the
3400 same time. However, Qt makes sure to never send duplicate QEvent::TouchBegin events to the same
3401 widget, which could theoretically happen during propagation if, for example, the user touched 2
3402 separate widgets in a QGroupBox and both widgets ignored the QEvent::TouchBegin event.
3404 To avoid this, Qt will group new touch points together using the following rules:
3408 \i When the first touch point is detected, the destination widget is determined firstly by the
3409 location on screen and secondly by the propagation rules.
3411 \i When additional touch points are detected, Qt first looks to see if there are any active
3412 touch points on any ancestor or descendent of the widget under the new touch point. If there
3413 are, the new touch point is grouped with the first, and the new touch point will be sent in a
3414 single QTouchEvent to the widget that handled the first touch point. (The widget under the new
3415 touch point will not receive an event).
3419 This makes it possible for sibling widgets to handle touch events independently while making
3420 sure that the sequence of QTouchEvents is always correct.
3422 \section1 Mouse Events and Touch Event synthesizing
3424 QTouchEvent delivery is independent from that of QMouseEvent. The application flags
3425 Qt::AA_SynthesizeTouchForUnhandledMouseEvents and Qt::AA_SynthesizeMouseForUnhandledTouchEvents
3426 can be used to enable or disable automatic synthesizing of touch events to mouse events and
3427 mouse events to touch events.
3433 \i As mentioned above, enabling touch events means multiple widgets can be receiving touch
3434 events simultaneously. Combined with the default QWidget::event() handling for QTouchEvents,
3435 this gives you great flexibility in designing touch user interfaces. Be aware of the
3436 implications. For example, it is possible that the user is moving a QSlider with one finger and
3437 pressing a QPushButton with another. The signals emitted by these widgets will be
3440 \i Recursion into the event loop using one of the exec() methods (e.g., QDialog::exec() or
3441 QMenu::exec()) in a QTouchEvent event handler is not supported. Since there are multiple event
3442 recipients, recursion may cause problems, including but not limited to lost events
3443 and unexpected infinite recursion.
3445 \i QTouchEvents are not affected by a \l{QWidget::grabMouse()}{mouse grab} or an
3446 \l{QApplication::activePopupWidget()}{active pop-up widget}. The behavior of QTouchEvents is
3447 undefined when opening a pop-up or grabbing the mouse while there are more than one active touch
3452 \sa QTouchEvent::TouchPoint, Qt::TouchPointState, Qt::WA_AcceptTouchEvents,
3453 QGraphicsItem::acceptTouchEvents()
3456 /*! \enum Qt::TouchPointState
3459 This enum represents the state of a touch point at the time the
3460 QTouchEvent occurred.
3462 \value TouchPointPressed The touch point is now pressed.
3463 \value TouchPointMoved The touch point moved.
3464 \value TouchPointStationary The touch point did not move.
3465 \value TouchPointReleased The touch point was released.
3468 /*! \enum QTouchEvent::DeviceType
3470 This enum represents the type of device that generated a QTouchEvent.
3472 This enum has been deprecated. Use QTouchDevice::DeviceType instead.
3474 \sa QTouchDevice::DeviceType, QTouchDevice::type(), QTouchEvent::device()
3478 Constructs a QTouchEvent with the given \a eventType, \a deviceType, \a
3479 touchPoints and \a device. The \a touchPointStates and \a modifiers
3480 are the current touch point states and keyboard modifiers at the time of
3483 QTouchEvent::QTouchEvent(QEvent::Type eventType,
3484 QTouchDevice *device,
3485 Qt::KeyboardModifiers modifiers,
3486 Qt::TouchPointStates touchPointStates,
3487 const QList<QTouchEvent::TouchPoint> &touchPoints)
3488 : QInputEvent(eventType, modifiers),
3492 _touchPointStates(touchPointStates),
3493 _touchPoints(touchPoints)
3497 Destroys the QTouchEvent.
3499 QTouchEvent::~QTouchEvent()
3502 /*! \fn QWindow *QTouchEvent::window() const
3504 Returns the window on which the event occurred. Useful for doing
3505 global-local mapping on data like rawScreenPositions() which,
3506 for performance reasons, only stores the global positions in the
3510 /*! \fn QObject *QTouchEvent::target() const
3512 Returns the target object within the window on which the event occurred.
3513 This is typically a QWidget or a QQuickItem. May be 0 when no specific target is available.
3516 /*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const
3518 Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}.
3520 This function has been deprecated. Use QTouchDevice::type() instead.
3522 \sa QTouchDevice::type(), QTouchEvent::device()
3525 /*! \fn Qt::TouchPointStates QTouchEvent::touchPointStates() const
3527 Returns a bitwise OR of all the touch point states for this event.
3530 /*! \fn const QList<QTouchEvent::TouchPoint> &QTouchEvent::touchPoints() const
3532 Returns the list of touch points contained in the touch event.
3535 /*! \fn QTouchEvent::DeviceType QTouchEvent::deviceType() const
3537 Returns the touch device Type, which is of type \l {QTouchEvent::DeviceType} {DeviceType}.
3540 /*! \fn QTouchDevice* QTouchEvent::device() const
3542 Returns the touch device from which this touch event originates.
3545 /*! \fn void QTouchEvent::setWindow(QWindow *window)
3549 Sets the window for this event.
3552 /*! \fn void QTouchEvent::setTarget(QObject *target)
3556 Sets the target within the window (typically a widget) for this event.
3559 /*! \fn void QTouchEvent::setTouchPointStates(Qt::TouchPointStates touchPointStates)
3563 Sets a bitwise OR of all the touch point states for this event.
3566 /*! \fn void QTouchEvent::setTouchPoints(const QList<QTouchEvent::TouchPoint> &touchPoints)
3570 Sets the list of touch points for this event.
3573 /*! \fn void QTouchEvent::setDeviceType(DeviceType deviceType)
3577 Sets the device type to \a deviceType, which is of type \l {QTouchEvent::DeviceType}
3581 /*! \fn void QTouchEvent::setTouchDevice(QTouchDevice *device)
3585 Sets the touch event's device to the given one.
3588 /*! \class QTouchEvent::TouchPoint
3589 \brief The TouchPoint class provides information about a touch point in a QTouchEvent.
3593 /*! \enum QTouchEvent::TouchPoint::InfoFlags
3595 The values of this enum describe additional information about a touch point.
3597 \value Pen Indicates that the contact has been made by a designated pointing device (e.g. a pen) instead of a finger.
3602 Constructs a QTouchEvent::TouchPoint for use in a QTouchEvent.
3604 QTouchEvent::TouchPoint::TouchPoint(int id)
3605 : d(new QTouchEventTouchPointPrivate(id))
3610 Constructs a copy of \a other.
3612 QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
3620 Destroys the QTouchEvent::TouchPoint.
3622 QTouchEvent::TouchPoint::~TouchPoint()
3624 if (!d->ref.deref())
3629 Returns the id number of this touch point.
3631 Do not assume that id numbers start at zero or that they are sequential.
3632 Such an assumption is often false due to the way the underlying drivers work.
3634 int QTouchEvent::TouchPoint::id() const
3640 Returns the current state of this touch point.
3642 Qt::TouchPointState QTouchEvent::TouchPoint::state() const
3644 return Qt::TouchPointState(int(d->state));
3648 Returns the position of this touch point, relative to the widget
3649 or QGraphicsItem that received the event.
3651 \sa startPos(), lastPos(), screenPos(), scenePos(), normalizedPos()
3653 QPointF QTouchEvent::TouchPoint::pos() const
3655 return d->rect.center();
3659 Returns the scene position of this touch point.
3661 The scene position is the position in QGraphicsScene coordinates
3662 if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
3663 reimplementation, and identical to the screen position for
3666 \sa startScenePos(), lastScenePos(), pos()
3668 QPointF QTouchEvent::TouchPoint::scenePos() const
3670 return d->sceneRect.center();
3674 Returns the screen position of this touch point.
3676 \sa startScreenPos(), lastScreenPos(), pos()
3678 QPointF QTouchEvent::TouchPoint::screenPos() const
3680 return d->screenRect.center();
3684 Returns the normalized position of this touch point.
3686 The coordinates are normalized to the size of the touch device,
3687 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
3689 \sa startNormalizedPos(), lastNormalizedPos(), pos()
3691 QPointF QTouchEvent::TouchPoint::normalizedPos() const
3693 return d->normalizedPos;
3697 Returns the starting position of this touch point, relative to the
3698 widget or QGraphicsItem that received the event.
3700 \sa pos(), lastPos()
3702 QPointF QTouchEvent::TouchPoint::startPos() const
3708 Returns the starting scene position of this touch point.
3710 The scene position is the position in QGraphicsScene coordinates
3711 if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
3712 reimplementation, and identical to the screen position for
3715 \sa scenePos(), lastScenePos()
3717 QPointF QTouchEvent::TouchPoint::startScenePos() const
3719 return d->startScenePos;
3723 Returns the starting screen position of this touch point.
3725 \sa screenPos(), lastScreenPos()
3727 QPointF QTouchEvent::TouchPoint::startScreenPos() const
3729 return d->startScreenPos;
3733 Returns the normalized starting position of this touch point.
3735 The coordinates are normalized to the size of the touch device,
3736 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
3738 \sa normalizedPos(), lastNormalizedPos()
3740 QPointF QTouchEvent::TouchPoint::startNormalizedPos() const
3742 return d->startNormalizedPos;
3746 Returns the position of this touch point from the previous touch
3747 event, relative to the widget or QGraphicsItem that received the event.
3749 \sa pos(), startPos()
3751 QPointF QTouchEvent::TouchPoint::lastPos() const
3757 Returns the scene position of this touch point from the previous
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(), startScenePos()
3767 QPointF QTouchEvent::TouchPoint::lastScenePos() const
3769 return d->lastScenePos;
3773 Returns the screen position of this touch point from the previous
3776 \sa screenPos(), startScreenPos()
3778 QPointF QTouchEvent::TouchPoint::lastScreenPos() const
3780 return d->lastScreenPos;
3784 Returns the normalized position of this touch point from the
3785 previous touch event.
3787 The coordinates are normalized to the size of the touch device,
3788 i.e. (0,0) is the top-left corner and (1,1) is the bottom-right corner.
3790 \sa normalizedPos(), startNormalizedPos()
3792 QPointF QTouchEvent::TouchPoint::lastNormalizedPos() const
3794 return d->lastNormalizedPos;
3798 Returns the rect for this touch point, relative to the widget
3799 or QGraphicsItem that received the event. The rect is centered
3800 around the point returned by pos().
3802 \note This function returns an empty rect if the device does not report touch point sizes.
3804 QRectF QTouchEvent::TouchPoint::rect() const
3810 Returns the rect for this touch point in scene coordinates.
3812 \note This function returns an empty rect if the device does not report touch point sizes.
3814 \sa scenePos(), rect()
3816 QRectF QTouchEvent::TouchPoint::sceneRect() const
3818 return d->sceneRect;
3822 Returns the rect for this touch point in screen coordinates.
3824 \note This function returns an empty rect if the device does not report touch point sizes.
3826 \sa screenPos(), rect()
3828 QRectF QTouchEvent::TouchPoint::screenRect() const
3830 return d->screenRect;
3834 Returns the pressure of this touch point. The return value is in
3835 the range 0.0 to 1.0.
3837 qreal QTouchEvent::TouchPoint::pressure() const
3843 Returns a velocity vector for this touch point.
3844 The vector is in the screen's coordinate system, using pixels per seconds for the magnitude.
3846 \note The returned vector is only valid if the touch device's capabilities include QTouchDevice::Velocity.
3848 \sa QTouchDevice::capabilities(), device()
3850 QVector2D QTouchEvent::TouchPoint::velocity() const
3856 Returns additional information about the touch point.
3858 \sa QTouchEvent::TouchPoint::InfoFlags
3860 QTouchEvent::TouchPoint::InfoFlags QTouchEvent::TouchPoint::flags() const
3866 Returns the raw, unfiltered positions for the touch point. The positions are in screen coordinates.
3867 To get local coordinates you can use mapFromGlobal() of the QWindow returned by QTouchEvent::window().
3869 \note Returns an empty list if the touch device's capabilities do not include QTouchDevice::RawPositions.
3871 \sa QTouchDevice::capabilities(), device(), window()
3873 QList<QPointF> QTouchEvent::TouchPoint::rawScreenPositions() const
3875 return d->rawScreenPositions;
3879 void QTouchEvent::TouchPoint::setId(int id)
3881 if (d->ref.load() != 1)
3887 void QTouchEvent::TouchPoint::setState(Qt::TouchPointStates state)
3889 if (d->ref.load() != 1)
3895 void QTouchEvent::TouchPoint::setPos(const QPointF &pos)
3897 if (d->ref.load() != 1)
3899 d->rect.moveCenter(pos);
3903 void QTouchEvent::TouchPoint::setScenePos(const QPointF &scenePos)
3905 if (d->ref.load() != 1)
3907 d->sceneRect.moveCenter(scenePos);
3911 void QTouchEvent::TouchPoint::setScreenPos(const QPointF &screenPos)
3913 if (d->ref.load() != 1)
3915 d->screenRect.moveCenter(screenPos);
3919 void QTouchEvent::TouchPoint::setNormalizedPos(const QPointF &normalizedPos)
3921 if (d->ref.load() != 1)
3923 d->normalizedPos = normalizedPos;
3927 void QTouchEvent::TouchPoint::setStartPos(const QPointF &startPos)
3929 if (d->ref.load() != 1)
3931 d->startPos = startPos;
3935 void QTouchEvent::TouchPoint::setStartScenePos(const QPointF &startScenePos)
3937 if (d->ref.load() != 1)
3939 d->startScenePos = startScenePos;
3943 void QTouchEvent::TouchPoint::setStartScreenPos(const QPointF &startScreenPos)
3945 if (d->ref.load() != 1)
3947 d->startScreenPos = startScreenPos;
3951 void QTouchEvent::TouchPoint::setStartNormalizedPos(const QPointF &startNormalizedPos)
3953 if (d->ref.load() != 1)
3955 d->startNormalizedPos = startNormalizedPos;
3959 void QTouchEvent::TouchPoint::setLastPos(const QPointF &lastPos)
3961 if (d->ref.load() != 1)
3963 d->lastPos = lastPos;
3967 void QTouchEvent::TouchPoint::setLastScenePos(const QPointF &lastScenePos)
3969 if (d->ref.load() != 1)
3971 d->lastScenePos = lastScenePos;
3975 void QTouchEvent::TouchPoint::setLastScreenPos(const QPointF &lastScreenPos)
3977 if (d->ref.load() != 1)
3979 d->lastScreenPos = lastScreenPos;
3983 void QTouchEvent::TouchPoint::setLastNormalizedPos(const QPointF &lastNormalizedPos)
3985 if (d->ref.load() != 1)
3987 d->lastNormalizedPos = lastNormalizedPos;
3991 void QTouchEvent::TouchPoint::setRect(const QRectF &rect)
3993 if (d->ref.load() != 1)
3999 void QTouchEvent::TouchPoint::setSceneRect(const QRectF &sceneRect)
4001 if (d->ref.load() != 1)
4003 d->sceneRect = sceneRect;
4007 void QTouchEvent::TouchPoint::setScreenRect(const QRectF &screenRect)
4009 if (d->ref.load() != 1)
4011 d->screenRect = screenRect;
4015 void QTouchEvent::TouchPoint::setPressure(qreal pressure)
4017 if (d->ref.load() != 1)
4019 d->pressure = pressure;
4023 void QTouchEvent::TouchPoint::setVelocity(const QVector2D &v)
4025 if (d->ref.load() != 1)
4031 void QTouchEvent::TouchPoint::setRawScreenPositions(const QList<QPointF> &positions)
4033 if (d->ref.load() != 1)
4035 d->rawScreenPositions = positions;
4039 void QTouchEvent::TouchPoint::setFlags(InfoFlags flags)
4041 if (d->ref.load() != 1)
4047 QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::TouchPoint &other)
4050 if (!d->ref.deref())
4058 \class QScrollPrepareEvent
4062 \brief The QScrollPrepareEvent class is send in preparation of a scrolling.
4064 The scroll prepare event is send before scrolling (usually by QScroller) is started.
4065 The object receiving this event should set viewportSize, maxContentPos and contentPos.
4066 It also should accept this event to indicate that scrolling should be started.
4068 It is not guaranteed that a QScrollEvent will be send after an acceepted
4069 QScrollPrepareEvent, e.g. in a case where the maximum content position is (0,0).
4071 \sa QScrollEvent, QScroller
4075 Creates new QScrollPrepareEvent
4076 The \a startPos is the position of a touch or mouse event that started the scrolling.
4078 QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos)
4079 : QEvent(QEvent::ScrollPrepare)
4081 d = reinterpret_cast<QEventPrivate *>(new QScrollPrepareEventPrivate());
4082 d_func()->startPos = startPos;
4086 Destroys QScrollEvent.
4088 QScrollPrepareEvent::~QScrollPrepareEvent()
4090 delete reinterpret_cast<QScrollPrepareEventPrivate *>(d);
4094 Returns the position of the touch or mouse event that started the scrolling.
4096 QPointF QScrollPrepareEvent::startPos() const
4098 return d_func()->startPos;
4102 Returns size of the area that is to be scrolled as set by setViewportSize
4104 \sa setViewportSize()
4106 QSizeF QScrollPrepareEvent::viewportSize() const
4108 return d_func()->viewportSize;
4112 Returns the range of coordinates for the content as set by setContentPosRange().
4114 QRectF QScrollPrepareEvent::contentPosRange() const
4116 return d_func()->contentPosRange;
4120 Returns the current position of the content as set by setContentPos.
4122 QPointF QScrollPrepareEvent::contentPos() const
4124 return d_func()->contentPos;
4129 Sets the size of the area that is to be scrolled to \a size.
4133 void QScrollPrepareEvent::setViewportSize(const QSizeF &size)
4135 d_func()->viewportSize = size;
4139 Sets the range of content coordinates to \a rect.
4141 \sa contentPosRange()
4143 void QScrollPrepareEvent::setContentPosRange(const QRectF &rect)
4145 d_func()->contentPosRange = rect;
4149 Sets the current content position to \a pos.
4153 void QScrollPrepareEvent::setContentPos(const QPointF &pos)
4155 d_func()->contentPos = pos;
4162 QScrollPrepareEventPrivate *QScrollPrepareEvent::d_func()
4164 return reinterpret_cast<QScrollPrepareEventPrivate *>(d);
4170 const QScrollPrepareEventPrivate *QScrollPrepareEvent::d_func() const
4172 return reinterpret_cast<const QScrollPrepareEventPrivate *>(d);
4180 \brief The QScrollEvent class is send when scrolling.
4182 The scroll event is send to indicate that the receiver should be scrolled.
4183 Usually the receiver should be something visual like QWidget or QGraphicsObject.
4185 Some care should be taken that no conflicting QScrollEvents are sent from two
4186 sources. Using QScroller::scrollTo is save however.
4188 \sa QScrollPrepareEvent, QScroller
4192 \enum QScrollEvent::ScrollState
4194 This enum describes the states a scroll event can have.
4196 \value ScrollStarted Set for the first scroll event of a scroll activity.
4198 \value ScrollUpdated Set for all but the first and the last scroll event of a scroll activity.
4200 \value ScrollFinished Set for the last scroll event of a scroll activity.
4202 \sa QScrollEvent::scrollState()
4206 Creates a new QScrollEvent
4207 \a contentPos is the new content position, \a overshootDistance is the
4208 new overshoot distance while \a scrollState indicates if this scroll
4209 event is the first one, the last one or some event in between.
4211 QScrollEvent::QScrollEvent(const QPointF &contentPos, const QPointF &overshootDistance, ScrollState scrollState)
4212 : QEvent(QEvent::Scroll)
4214 d = reinterpret_cast<QEventPrivate *>(new QScrollEventPrivate());
4215 d_func()->contentPos = contentPos;
4216 d_func()->overshoot= overshootDistance;
4217 d_func()->state = scrollState;
4221 Destroys QScrollEvent.
4223 QScrollEvent::~QScrollEvent()
4225 delete reinterpret_cast<QScrollEventPrivate *>(d);
4229 Returns the new scroll position.
4231 QPointF QScrollEvent::contentPos() const
4233 return d_func()->contentPos;
4237 Returns the new overshoot distance.
4238 See QScroller for an explanation of the term overshoot.
4242 QPointF QScrollEvent::overshootDistance() const
4244 return d_func()->overshoot;
4248 Returns the current scroll state as a combination of ScrollStateFlag values.
4249 ScrollStarted (or ScrollFinished) will be set, if this scroll event is the first (or last) event in a scrolling activity.
4250 Please note that both values can be set at the same time, if the activity consists of a single QScrollEvent.
4251 All other scroll events in between will have their state set to ScrollUpdated.
4253 A widget could for example revert selections when scrolling is started and stopped.
4255 QScrollEvent::ScrollState QScrollEvent::scrollState() const
4257 return d_func()->state;
4263 QScrollEventPrivate *QScrollEvent::d_func()
4265 return reinterpret_cast<QScrollEventPrivate *>(d);
4271 const QScrollEventPrivate *QScrollEvent::d_func() const
4273 return reinterpret_cast<const QScrollEventPrivate *>(d);
4277 Creates a new QScreenOrientationChangeEvent
4278 \a orientation is the new orientation of the screen.
4280 QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation screenOrientation)
4281 : QEvent(QEvent::OrientationChange)
4283 d = reinterpret_cast<QEventPrivate *>(new QScreenOrientationChangeEventPrivate());
4284 d_func()->screen = screen;
4285 d_func()->orientation = screenOrientation;
4289 Destroys QScreenOrientationChangeEvent.
4291 QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent()
4293 delete reinterpret_cast<QScrollEventPrivate *>(d);
4297 Returns the screen whose orientation changed.
4299 QScreen *QScreenOrientationChangeEvent::screen() const
4301 return d_func()->screen;
4305 Returns the orientation of the screen.
4307 Qt::ScreenOrientation QScreenOrientationChangeEvent::orientation() const
4309 return d_func()->orientation;
4315 QScreenOrientationChangeEventPrivate *QScreenOrientationChangeEvent::d_func()
4317 return reinterpret_cast<QScreenOrientationChangeEventPrivate *>(d);
4323 const QScreenOrientationChangeEventPrivate *QScreenOrientationChangeEvent::d_func() const
4325 return reinterpret_cast<const QScreenOrientationChangeEventPrivate *>(d);