1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the gui module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
31
#include "qapplication.h"
41
\brief The QInputEvent class is the base class for events that
48
QInputEvent::QInputEvent(Type type, Qt::KeyboardModifiers modifiers)
49
: QEvent(type), modState(modifiers)
55
QInputEvent::~QInputEvent()
60
\fn Qt::KeyboardModifiers QInputEvent::modifiers() const
62
Returns the keyboard modifier flags that existed immediately
63
before the event occurred.
65
\sa QApplication::keyboardModifiers()
72
\brief The QMouseEvent class contains parameters that describe a mouse event.
74
Mouse events occur when a mouse button is pressed or released
75
inside a widget, or when the mouse cursor is moved.
77
Mouse move events will occur only when a mouse button is pressed
78
down, unless mouse tracking has been enabled with
79
QWidget::setMouseTracking().
81
Qt automatically grabs the mouse when a mouse button is pressed
82
inside a widget; the widget will continue to receive mouse events
83
until the last mouse button is released.
85
A mouse event contains a special accept flag that indicates
86
whether the receiver wants the event. You should call ignore() if
87
the mouse event is not handled by your widget. A mouse event is
88
propagated up the parent widget chain until a widget accepts it
89
with accept(), or an event filter consumes it.
91
The state of the keyboard modifier keys can be found by calling the
92
\l{QInputEvent::modifiers()}{modifiers()} function, inhertied from
95
The functions pos(), x(), and y() give the cursor position
96
relative to the widget that receives the mouse event. If you
97
move the widget as a result of the mouse event, use the global
98
position returned by globalPos() to avoid a shaking motion.
100
The QWidget::setEnabled() function can be used to enable or
101
disable mouse and keyboard events for a widget.
103
Reimplement the QWidget event handlers, QWidget::mousePressEvent(),
104
QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(),
105
and QWidget::mouseMoveEvent() to receive mouse events in your own
108
\sa QWidget::setMouseTracking() QWidget::grabMouse()
113
Constructs a mouse event object.
115
The \a type parameter must be one of QEvent::MouseButtonPress,
116
QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
117
or QEvent::MouseMove.
119
The \a position is the mouse cursor's position relative to the
121
The \a button that caused the event is given as a value from
122
the \l Qt::ButtonState enum. If the event \a type is
123
\l MouseMove, the appropriate button for this event is Qt::NoButton.
124
The mouse and keyboard states at the time of the event are specified by
125
\a buttons and \a modifiers.
127
The globalPos() is initialized to QCursor::pos(), which may not
128
be appropriate. Use the other constructor to specify the global
132
QMouseEvent::QMouseEvent(Type type, const QPoint &position, Qt::MouseButton button,
133
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
134
: QInputEvent(type, modifiers), p(position), b(button), mouseState(buttons)
142
QMouseEvent::~QMouseEvent()
148
Use QMouseEvent(\a type, \a pos, \a button, \c mouseButtons, \c
149
keyboardModifiers) instead, where \c mouseButton is \a state &
150
Qt::MouseButtonMask and \c keyboardModifiers is \a state &
153
QMouseEvent::QMouseEvent(Type type, const QPoint &pos, Qt::ButtonState button, int state)
154
: QInputEvent(type), p(pos), b((Qt::MouseButton)button)
157
mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask);
158
modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
162
Use QMouseEvent(\a type, \a pos, \a globalPos, \a button,
163
\c mouseButtons, \c keyboardModifiers) instead, where
164
\c mouseButton is \a state & Qt::MouseButtonMask and
165
\c keyboardModifiers is \a state & Qt::KeyButtonMask.
167
QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
168
Qt::ButtonState button, int state)
169
: QInputEvent(type), p(pos), g(globalPos), b((Qt::MouseButton)button)
171
mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask);
172
modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
178
Constructs a mouse event object.
180
The \a type parameter must be QEvent::MouseButtonPress,
181
QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
182
or QEvent::MouseMove.
184
The \a pos is the mouse cursor's position relative to the
185
receiving widget. The cursor's position in global coordinates is
186
specified by \a globalPos. The \a button that caused the event is
187
given as a value from the \l Qt::MouseButton enum. If the event \a
188
type is \l MouseMove, the appropriate button for this event is
189
Qt::NoButton. \a buttons is the state of all buttons at the
190
time of the event, \a modifiers the state of all keyboard
194
QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
195
Qt::MouseButton button, Qt::MouseButtons buttons,
196
Qt::KeyboardModifiers modifiers)
197
: QInputEvent(type, modifiers), p(pos), g(globalPos), b(button), mouseState(buttons)
201
\fn const QPoint &QMouseEvent::pos() const
203
Returns the position of the mouse cursor, relative to the widget
204
that received the event.
206
If you move the widget as a result of the mouse event, use the
207
global position returned by globalPos() to avoid a shaking
210
\sa x() y() globalPos()
214
\fn const QPoint &QMouseEvent::globalPos() const
216
Returns the global position of the mouse cursor \e{at the time
217
of the event}. This is important on asynchronous window systems
218
like X11. Whenever you move your widgets around in response to
219
mouse events, globalPos() may differ a lot from the current
220
pointer position QCursor::pos(), and from
221
QWidget::mapToGlobal(pos()).
223
\sa globalX() globalY()
227
\fn int QMouseEvent::x() const
229
Returns the x position of the mouse cursor, relative to the
230
widget that received the event.
236
\fn int QMouseEvent::y() const
238
Returns the y position of the mouse cursor, relative to the
239
widget that received the event.
245
\fn int QMouseEvent::globalX() const
247
Returns the global x position of the mouse cursor at the time of
250
\sa globalY() globalPos()
254
\fn int QMouseEvent::globalY() const
256
Returns the global y position of the mouse cursor at the time of
259
\sa globalX() globalPos()
263
\fn Qt::MouseButton QMouseEvent::button() const
265
Returns the button that caused the event.
267
Possible return values are Qt::LeftButton, Qt::RightButton,
268
Qt::MidButton, and Qt::NoButton.
270
Note that the returned value is always Qt::NoButton for mouse
273
\sa buttons() Qt::MouseButton
277
\fn Qt::MouseButton QMouseEvent::buttons() const
279
Returns the button state when the event was generated. The button
280
state is a combination of Qt::LeftButton, Qt::RightButton,
281
Qt::MidButton using the OR operator. For mouse move events,
282
this is all buttons that are pressed down. For mouse press and
283
double click events this includes the button that caused the
284
event. For mouse release events this excludes the button that
287
\sa button() Qt::MouseButton
292
\fn Qt::ButtonState QMouseEvent::state() const
294
Returns the button state immediately before the event was
295
generated. The button state is a combination of mouse buttons
296
(see Qt::ButtonState) and keyboard modifiers (Qt::MouseButtons).
298
Use buttons() and/or modifiers() instead. Be aware that buttons()
299
return the state immediately \e after the event was generated.
303
\fn Qt::ButtonState QMouseEvent::stateAfter() const
305
Returns the button state immediately after the event was
306
generated. The button state is a combination of mouse buttons
307
(see Qt::ButtonState) and keyboard modifiers (Qt::MouseButtons).
309
Use buttons() and/or modifiers() instead.
317
\brief The QHoverEvent class contains parameters that describe a mouse event.
319
Mouse events occur when a mouse cursor is moved into, out of, or within a
320
widget, and if the widget has the Qt::WA_Hover attribute.
322
The function pos() gives the current cursor position, while oldPos() gives
323
the old mouse position.
327
\fn const QPoint &QHoverEvent::pos() const
329
Returns the position of the mouse cursor, relative to the widget
330
that received the event.
332
On QEvent::HoverLeave events, this position will always be
339
\fn const QPoint &QHoverEvent::oldPos() const
341
Returns the previous position of the mouse cursor, relative to the widget
342
that received the event. If there is no previous position, oldPos() will
343
return the same position as pos().
345
On QEvent::HoverEnter events, this position will always be
352
Constructs a hover event object.
354
The \a type parameter must be QEvent::HoverEnter,
355
QEvent::HoverLeave, or QEvent::HoverMove.
357
The \a pos is the current mouse cursor's position relative to the
358
receiving widget, while \a oldPos is the previous mouse cursor's
359
position relative to the receiving widget.
361
QHoverEvent::QHoverEvent(Type type, const QPoint &pos, const QPoint &oldPos)
362
: QEvent(type), p(pos), op(oldPos)
369
QHoverEvent::~QHoverEvent()
376
\brief The QWheelEvent class contains parameters that describe a wheel event.
380
Wheel events are sent to the widget under the mouse cursor, but
381
if that widget does not handle the event they are sent to the
382
focus widget. The rotation distance is provided by delta().
383
The functions pos() and globalPos() return the mouse cursor's
384
location at the time of the event.
386
A wheel event contains a special accept flag that indicates
387
whether the receiver wants the event. You should call ignore() if
388
you do not handle the wheel event; this ensures that it will be
389
sent to the parent widget.
391
The QWidget::setEnabled() function can be used to enable or
392
disable mouse and keyboard events for a widget.
394
The event handler QWidget::wheelEvent() receives wheel events.
396
\sa QMouseEvent QWidget::grabMouse()
400
\fn Qt::MouseButtons QWheelEvent::buttons() const
402
Returns the mouse state when the event occurred.
406
\fn Qt::Orientation QWheelEvent::orientation() const
408
Returns the wheel's orientation.
412
Constructs a wheel event object.
414
The position, \a pos, is the location of the mouse cursor within
415
the widget. The globalPos() is initialized to QCursor::pos()
416
which is usually, but not always, correct.
417
Use the other constructor if you need to specify the global
420
The \a buttons describe the state of the mouse buttons at the time
421
of the event, \a delta contains the rotation distance,
422
\a modifiers holds the keyboard modifier flags at the time of the
423
event, and \a orient holds the wheel's orientation.
425
\sa pos() delta() state()
427
#ifndef QT_NO_WHEELEVENT
428
QWheelEvent::QWheelEvent(const QPoint &pos, int delta,
429
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
430
Qt::Orientation orient)
431
: QInputEvent(Wheel, modifiers), p(pos), d(delta), mouseState(buttons), o(orient)
439
QWheelEvent::~QWheelEvent()
445
Use one of the other constructors instead.
447
QWheelEvent::QWheelEvent(const QPoint &pos, int delta, int state, Qt::Orientation orient)
448
: QInputEvent(Wheel), p(pos), d(delta), o(orient)
451
mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask);
452
modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);
457
Constructs a wheel event object.
459
The \a pos provides the location of the mouse cursor
460
within the widget. The position in global coordinates is specified
461
by \a globalPos. \a delta contains the rotation distance, \a modifiers
462
holds the keyboard modifier flags at the time of the event, and
463
\a orient holds the wheel's orientation.
465
\sa pos() globalPos() delta() state()
467
QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta,
468
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
469
Qt::Orientation orient)
470
: QInputEvent(Wheel, modifiers), p(pos), g(globalPos), d(delta), mouseState(buttons), o(orient)
475
Use one of the other constructors instead.
477
QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, int state,
478
Qt::Orientation orient)
479
: QInputEvent(Wheel), p(pos), g(globalPos), d(delta), o(orient)
481
mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask);
482
modState = Qt::KeyboardModifiers(state & (int) Qt::KeyButtonMask);
485
#endif // QT_NO_WHEELEVENT
488
\fn int QWheelEvent::delta() const
490
Returns the distance that the wheel is rotated, given in
491
multiples or divisions of \c WHEEL_DELTA. A positive value
492
indicates that the wheel was rotated forwards away from the
493
user; a negative value indicates that the wheel was rotated
494
backwards toward the user.
496
The \c WHEEL_DELTA constant was defined to be 120 by the wheel
497
mouse vendors to allow finer-resolution wheels to be built in
498
the future, such as a freely rotating wheel with no notches.
499
The expectation is that such a device would send more messages
500
per rotation, but with a smaller value in each message.
504
\fn const QPoint &QWheelEvent::pos() const
506
Returns the position of the mouse cursor relative to the widget
507
that received the event.
509
If you move your widgets around in response to mouse events,
510
use globalPos() instead of this function.
512
\sa x() y() globalPos()
516
\fn int QWheelEvent::x() const
518
Returns the x position of the mouse cursor, relative to the
519
widget that received the event.
525
\fn int QWheelEvent::y() const
527
Returns the y position of the mouse cursor, relative to the
528
widget that received the event.
535
\fn const QPoint &QWheelEvent::globalPos() const
537
Returns the global position of the mouse pointer \e{at the time
538
of the event}. This is important on asynchronous window systems
539
such as X11; whenever you move your widgets around in response to
540
mouse events, globalPos() can differ a lot from the current
541
cursor position returned by QCursor::pos().
543
\sa globalX() globalY()
547
\fn int QWheelEvent::globalX() const
549
Returns the global x position of the mouse cursor at the time of
552
\sa globalY() globalPos()
556
\fn int QWheelEvent::globalY() const
558
Returns the global y position of the mouse cursor at the time of
561
\sa globalX() globalPos()
566
\fn Qt::ButtonState QWheelEvent::state() const
568
Returns the keyboard modifier flags at the time of the event.
570
The returned value is a selection of the following values,
571
combined using the OR operator: Qt::ShiftButton,
572
Qt::ControlButton, and Qt::AltButton.
578
\brief The QKeyEvent class contains describes a key event.
582
Key events are sent to the widget with keyboard input focus
583
when keys are pressed or released.
585
A key event contains a special accept flag that indicates whether
586
the receiver will handle the key event. You should call ignore()
587
if the key press or release event is not handled by your widget.
588
A key event is propagated up the parent widget chain until a
589
widget accepts it with accept() or an event filter consumes it.
590
Key events for multimedia keys are ignored by default. You should
591
call accept() if your widget handles those events.
593
The QWidget::setEnable() function can be used to enable or disable
594
mouse and keyboard events for a widget.
596
The event handlers QWidget::keyPressEvent() and
597
QWidget::keyReleaseEvent() receive key events.
599
\sa QFocusEvent, QWidget::grabKeyboard()
603
Constructs a key event object.
605
The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
606
or QEvent::ShortcutOverride.
608
If \a key is 0, the event is not a result of
609
a known key; for example, it may be the result of a compose
610
sequence or keyboard macro. The \a modifiers holds the keyboard
611
modifiers, and the given \a text is the Unicode text that the
612
key generated. If \a autorep is true, isAutoRepeat() will be
613
true. \a count is the number of keys involved in the event.
615
QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
616
bool autorep, ushort count)
617
: QInputEvent(type, modifiers), txt(text), k(key), c(count), autor(autorep)
624
QKeyEvent::~QKeyEvent()
629
\fn int QKeyEvent::key() const
631
Returns the code of the key that was pressed or released.
633
See \l Qt::Key for the list of keyboard codes. These codes are
634
independent of the underlying window system.
636
A value of either 0 or Qt::Key_unknown means that the event is not
637
the result of a known key; for example, it may be the result of
638
a compose sequence, a keyboard macro, or due to key event
641
\sa Qt::WA_KeyCompression
645
\fn QString QKeyEvent::text() const
647
Returns the Unicode text that this key generated. The text
648
returned can be an empty string in cases
649
where modifier keys, such as Shift, Control, Alt, and Meta,
650
are being pressed or released. In such cases key() will contain
653
\sa Qt::WA_KeyCompression
657
Returns the keyboard modifier flags that existed immediately
658
after the event occurred.
660
\warning This function cannot always be trusted. The user can
661
confuse it by pressing both \key{Shift} keys pressed
662
simulatenously and releasing one of them, for example.
664
\sa QApplication::keyboardModifiers()
666
//###### We must check with XGetModifierMapping
667
Qt::KeyboardModifiers QKeyEvent::modifiers() const
669
if (key() == Qt::Key_Shift)
670
return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ShiftModifier);
671
if (key() == Qt::Key_Control)
672
return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ControlModifier);
673
if (key() == Qt::Key_Alt)
674
return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::AltModifier);
675
if (key() == Qt::Key_Meta)
676
return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::MetaModifier);
677
return QInputEvent::modifiers();
681
\fn bool QKeyEvent::isAutoRepeat() const
683
Returns true if this event comes from an auto-repeating key;
684
returns false if it comes from an initial key press.
686
Note that if the event is a multiple-key compressed event that is
687
partly due to auto-repeat, this function could return either true
688
or false indeterminately.
692
\fn int QKeyEvent::count() const
694
Returns the number of keys involved in this event. If text()
695
is not empty, this is simply the length of the string.
697
\sa Qt::WA_KeyCompression
702
\fn QKeyEvent::QKeyEvent(Type type, int key, int ascii,
703
int modifiers, const QString &text,
704
bool autorep, ushort count)
706
Use one of the other constructors instead.
710
\fn int QKeyEvent::ascii() const
716
\fn Qt::ButtonState QKeyEvent::state() const
718
Use QInputEvent::modifiers() instead.
722
\fn Qt::ButtonState QKeyEvent::stateAfter() const
724
Use modifiers() instead.
730
\brief The QFocusEvent class contains event parameters for widget focus
735
Focus events are sent to widgets when the keyboard input focus
736
changes. Focus events occur due to mouse actions, key presses
737
(such as \gui{Tab} or \gui{Backtab}), the window system, popup
738
menus, keyboard shortcuts, or other application-specific reasons.
739
The reason for a particular focus event is returned by reason()
740
in the appropriate event handler.
742
The event handlers QWidget::focusInEvent() and
743
QWidget::focusOutEvent() receive focus events.
745
\sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus}
749
Constructs a focus event object.
751
The \a type parameter must be either QEvent::FocusIn or
752
QEvent::FocusOut. The \a reason describes the cause of the change
755
QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason)
756
: QEvent(type), m_reason(reason)
762
QFocusEvent::~QFocusEvent()
767
Returns the reason for this focus event.
769
Qt::FocusReason QFocusEvent::reason()
775
\fn bool QFocusEvent::gotFocus() const
777
Returns true if type() is QEVent::FocusIn; otherwise returns
782
\fn bool QFocusEvent::lostFocus() const
784
Returns true if type() is QEVent::FocusOut; otherwise returns
790
\enum QFocusEvent::Reason
793
Use Qt::FocusReason instead.
795
\value Mouse Same as Qt::MouseFocusReason.
796
\value Tab Same as Qt::TabFocusReason.
797
\value Backtab Same as Qt::BacktabFocusReason.
798
\value MenuBar Same as Qt::MenuBarFocusReason.
799
\value ActiveWindow Same as Qt::ActiveWindowFocusReason
800
\value Other Same as Qt::OtherFocusReason
801
\value Popup Same as Qt::PopupFocusReason
802
\value Shortcut Same as Qt::ShortcutFocusReason
808
\brief The QPaintEvent class contains event parameters for paint events.
812
Paint events are sent to widgets that need to update themselves,
813
for instance when part of a widget is exposed because a covering
816
The event contains a region() that needs to be updated, and a
817
rect() that is the bounding rectangle of that region. Both are
818
provided because many widgets can't make much use of region(),
819
and rect() can be much faster than region().boundingRect().
820
Painting is clipped to region() during the processing of a paint
823
\sa QPainter, QWidget::update(), QWidget::repaint(),
824
QWidget::paintEvent()
828
\fn bool QPaintEvent::erased() const
831
Returns true if the paint event region (or rectangle) has been
832
erased with the widget's background; otherwise returns false.
834
Qt 4 \e always erases regions that require painting. The exception
835
to this rule is if the widget sets the Qt::WA_NoBackground or
836
Qt::WA_NoSystemBackground attributes. If either one of those
837
attributes is set \e and the window system does not make use of
838
subwidget alpha composition (currently X11 and Windows, but this
839
may change), then the region is not erased.
843
\fn void QPaintEvent::setErased(bool b) { m_erased = b; }
848
Constructs a paint event object with the region that needs to
849
be updated. The region is specified by \a paintRegion.
851
QPaintEvent::QPaintEvent(const QRegion& paintRegion)
852
: QEvent(Paint), m_rect(paintRegion.boundingRect()), m_region(paintRegion), m_erased(false)
856
Constructs a paint event object with the rectangle that needs
857
to be updated. The region is specified by \a paintRect.
859
QPaintEvent::QPaintEvent(const QRect &paintRect)
860
: QEvent(Paint), m_rect(paintRect),m_region(paintRect), m_erased(false)
866
Constructs a paint event object with both a \a paintRegion and a
867
\a paintRect, both of which represent the area of the widget that
871
QPaintEvent::QPaintEvent(const QRegion &paintRegion, const QRect &paintRect)
872
: QEvent(Paint), m_rect(paintRect), m_region(paintRegion), m_erased(false)
879
QPaintEvent::~QPaintEvent()
884
\fn const QRect &QPaintEvent::rect() const
886
Returns the rectangle that needs to be updated.
888
\sa region() QPainter::setClipRect()
892
\fn const QRegion &QPaintEvent::region() const
894
Returns the region that needs to be updated.
896
\sa rect() QPainter::setClipRegion()
901
QWSUpdateEvent::QWSUpdateEvent(const QRegion& paintRegion)
902
: QPaintEvent(paintRegion)
905
QWSUpdateEvent::QWSUpdateEvent(const QRect &paintRect)
906
: QPaintEvent(paintRect)
909
QWSUpdateEvent::~QWSUpdateEvent()
917
\brief The QMoveEvent class contains event parameters for move events.
921
Move events are sent to widgets that have been moved to a new
922
position relative to their parent.
924
The event handler QWidget::moveEvent() receives move events.
926
\sa QWidget::move(), QWidget::setGeometry()
930
Constructs a move event with the new and old widget positions,
931
\a pos and \a oldPos respectively.
933
QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos)
934
: QEvent(Move), p(pos), oldp(oldPos)
940
QMoveEvent::~QMoveEvent()
945
\fn const QPoint &QMoveEvent::pos() const
947
Returns the new position of the widget. This excludes the window
948
frame for top level widgets.
952
\fn const QPoint &QMoveEvent::oldPos() const
954
Returns the old position of the widget.
960
\brief The QResizeEvent class contains event parameters for resize events.
964
Resize events are sent to widgets that have been resized.
966
The event handler QWidget::resizeEvent() receives resize events.
968
\sa QWidget::resize() QWidget::setGeometry()
972
Constructs a resize event with the new and old widget sizes, \a
973
size and \a oldSize respectively.
975
QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
976
: QEvent(Resize), s(size), olds(oldSize)
982
QResizeEvent::~QResizeEvent()
987
\fn const QSize &QResizeEvent::size() const
989
Returns the new size of the widget. This is the same as
994
\fn const QSize &QResizeEvent::oldSize() const
996
Returns the old size of the widget.
1002
\brief The QCloseEvent class contains parameters that describe a close event.
1006
Close events are sent to widgets that the user wants to close,
1007
usually by choosing "Close" from the window menu, or by clicking
1008
the \gui{X} title bar button. They are also sent when you call
1009
QWidget::close() to close a widget programmatically.
1011
Close events contain a flag that indicates whether the receiver
1012
wants the widget to be closed or not. When a widget accepts the
1013
close event, it is hidden (and destroyed if it was created with
1014
the Qt::WA_DeleteOnClose flag). If it refuses to accept the close
1015
event nothing happens. (Under X11 it is possible that the window
1016
manager will forcibly close the window; but at the time of writing
1017
we are not aware of any window manager that does this.)
1019
The event handler QWidget::closeEvent() receives close events. The
1020
default implementation of this event handler accepts the close
1021
event. If you do not want your widget to be hidden, or want some
1022
special handing, you should reimplement the event handler and
1025
The \l{mainwindows/application#close event handler}{closeEvent() in the
1026
Application example} shows a close event handler that
1027
asks whether to save a document before closing.
1029
If you want the widget to be deleted when it is closed, create it
1030
with the Qt::WA_DeleteOnClose flag. This is very useful for
1031
independent top-level windows in a multi-window application.
1033
\l{QObject}s emits the \l{QObject::destroyed()}{destroyed()}
1034
signal when they are deleted.
1036
If the last top-level window is closed, the
1037
QApplication::lastWindowClosed() signal is emitted.
1039
The isAccepted() function returns true if the event's receiver has
1040
agreed to close the widget; call accept() to agree to close the
1041
widget and call ignore() if the receiver of this event does not
1042
want the widget to be closed.
1044
\sa QWidget::close(), QWidget::hide(), QObject::destroyed(),
1045
QApplication::setMainWidget(), QApplication::lastWindowClosed(),
1046
QApplication::exec(), QApplication::quit()
1050
Constructs a close event object.
1054
QCloseEvent::QCloseEvent()
1060
QCloseEvent::~QCloseEvent()
1065
\class QIconDragEvent
1066
\brief The QIconDragEvent class indicates that a main icon drag has begun.
1070
Icon drag events are sent to widgets when the main icon of a window
1071
has been dragged away. On Mac OS X, this happens when the proxy
1072
icon of a window is dragged off the title bar.
1074
It is normal to begin using drag and drop in response to this
1077
\sa {Drag and Drop}, QMimeData, QDrag
1081
Constructs an icon drag event object with the accept flag set to
1086
QIconDragEvent::QIconDragEvent()
1091
QIconDragEvent::~QIconDragEvent()
1096
\class QContextMenuEvent
1097
\brief The QContextMenuEvent class contains parameters that describe a context menu event.
1101
Context menu events are sent to widgets when a user performs
1102
an action associated with opening a context menu.
1103
The actions required to open context menus vary between platforms;
1104
for example, on Windows, pressing the menu button or clicking the
1105
right mouse button will cause this event to be sent.
1107
When this event occurs it is customary to show a QMenu with a
1108
context menu, if this is relevant to the context.
1110
Context menu events contain a special accept flag that indicates
1111
whether the receiver accepted the event. If the event handler does
1112
not accept the event then, if possible, whatever triggered the event will be
1113
handled as a regular input event.
1117
Constructs a context menu event object with the accept parameter
1120
The \a reason parameter must be QContextMenuEvent::Mouse or
1121
QContextMenuEvent::Keyboard.
1123
The \a pos parameter specifies the mouse position relative to the
1124
receiving widget. \a globalPos is the mouse position in absolute
1127
QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
1128
: QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
1133
Constructs a context menu event with the given \a reason for the
1134
position specified by \a pos in widget coordinates and \a globalPos
1135
in global screen coordinates. \a dummy is ignored.
1137
QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
1139
: QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
1144
QContextMenuEvent::~QContextMenuEvent()
1148
Constructs a context menu event object with the accept parameter
1151
The \a reason parameter must be QContextMenuEvent::Mouse or
1152
QContextMenuEvent::Keyboard.
1154
The \a pos parameter specifies the mouse position relative to the
1157
The globalPos() is initialized to QCursor::pos(), which may not be
1158
appropriate. Use the other constructor to specify the global
1159
position explicitly.
1161
QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
1162
: QInputEvent(ContextMenu), p(pos), reas(reason)
1164
gp = QCursor::pos();
1169
Constructs a context menu event with the given \a reason for the
1170
position specified by \a pos in widget coordinates. \a dummy is
1173
QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, int /* dummy */)
1174
: QInputEvent(ContextMenu), p(pos), reas(reason)
1176
gp = QCursor::pos();
1179
Qt::ButtonState QContextMenuEvent::state() const
1181
return Qt::ButtonState(int(QApplication::keyboardModifiers())|QApplication::mouseButtons());
1186
\fn const QPoint &QContextMenuEvent::pos() const
1188
Returns the position of the mouse pointer relative to the widget
1189
that received the event.
1191
\sa x(), y(), globalPos()
1195
\fn int QContextMenuEvent::x() const
1197
Returns the x position of the mouse pointer, relative to the
1198
widget that received the event.
1204
\fn int QContextMenuEvent::y() const
1206
Returns the y position of the mouse pointer, relative to the
1207
widget that received the event.
1213
\fn const QPoint &QContextMenuEvent::globalPos() const
1215
Returns the global position of the mouse pointer at the time of
1222
\fn int QContextMenuEvent::globalX() const
1224
Returns the global x position of the mouse pointer at the time of
1227
\sa globalY(), globalPos()
1231
\fn int QContextMenuEvent::globalY() const
1233
Returns the global y position of the mouse pointer at the time of
1236
\sa globalX(), globalPos()
1240
\fn Qt::ButtonState QContextMenuEvent::state() const
1242
Returns the button state (a combination of mouse buttons
1243
and keyboard modifiers) immediately before the event was
1246
The returned value is a selection of the following values,
1247
combined with the OR operator:
1248
Qt::LeftButton, Qt::RightButton, Qt::MidButton,
1249
Qt::ShiftButton, Qt::ControlButton, and Qt::AltButton.
1253
\enum QContextMenuEvent::Reason
1255
This enum describes the reason why the event was sent.
1257
\value Mouse The mouse caused the event to be sent. Normally this
1258
means the right mouse button was clicked, but this is platform
1261
\value Keyboard The keyboard caused this event to be sent. On
1262
Windows, this means the menu button was pressed.
1264
\value Other The event was sent by some other means (i.e. not by
1265
the mouse or keyboard).
1270
\fn QContextMenuEvent::Reason QContextMenuEvent::reason() const
1272
Returns the reason for this context event.
1277
\class QInputMethodEvent
1278
\brief The QInputMethodEvent class provides parameters for input method events.
1282
Input method events are sent to widgets when an input method is
1283
used to enter text into a widget. Input methods are widely used
1284
to enter text for languages with non-Latin alphabets.
1286
The events are of interest to authors of keyboard entry widgets
1287
who want to be able to correctly handle languages with complex
1288
character input. Text input in such languages is usually a three
1292
\o \bold{Starting to Compose}
1294
When the user presses the first key on a keyboard, an input
1295
context is created. This input context will contain a string
1296
of the typed characters.
1300
With every new key pressed, the input method will try to create a
1301
matching string for the text typed so far called preedit
1302
string. While the input context is active, the user can only move
1303
the cursor inside the string belonging to this input context.
1305
\o \bold{Completing}
1307
At some point, the user will activate a user interface component
1308
(perhaps using a particular key) where they can choose from a
1309
number of strings matching the text they have typed so far. The
1310
user can either confirm their choice cancel the input; in either
1311
case the input context will be closed.
1314
QInputMethodEvent models these three stages, and transfers the
1315
information needed to correctly render the intermediate result. A
1316
QInputMethodEvent has two main parameters: preeditString() and
1317
commitString(). The preeditString() parameter gives the currently
1318
active preedit string. The commitString() parameter gives a text
1319
that should get added to (or replace parts of) the text of the
1320
editor widget. It usually is a result of the input operations and
1321
has to be inserted to the widgets text directly before the preedit
1324
If the commitString() should replace parts of the of the text in
1325
the editor, replacementLength() will contain the number of
1326
characters to be replaced. replacementStart() contains the position
1327
at which characters are to be replaced relative from the start of
1330
A number of attributes control the visual appearance of the
1331
preedit string (the visual appearance of text outside the preedit
1332
string is controlled by the widget only). The AttributeType enum
1333
describes the different attributes that can be set.
1335
A class implementing QWidget::inputMethodEvent() should at least
1336
understand and honor the \l TextFormat and \l Cursor attributes.
1338
Since input methods need to be able to query certain properties
1339
from the widget, the widget must also implement
1340
QWidget::inputMethodQuery().
1342
When receiving an input method event, the text widget has to performs the
1346
\o If the widget has selected text, the selected text should get
1349
\o Remove the text starting at replacementStart() with length
1350
replacementLength() and replace it by the commitString(). If
1351
replacementLength() is 0, replacementStart() gives the insertion
1352
position for the commitString().
1354
When doing replacement the area of the preedit
1355
string is ignored, thus a replacement starting at -1 with a length
1356
of 2 will remove the last character before the preedit string and
1357
the first character afterwards, and insert the commit string
1358
directly before the preedit string.
1360
If the widget implements undo/redo, this operation gets added to
1363
\o If there is no current preedit string, insert the
1364
preeditString() at the current cursor position; otherwise replace
1365
the previous preeditString with the one received from this event.
1367
If the widget implements undo/redo, the preeditString() should not
1368
influence the undo/redo stack in any way.
1370
The widget should examine the list of attributes to apply to the
1371
preedit string. It has to understand at least the TextFormat and
1372
Cursor attributes and render them as specified.
1379
\enum QInputMethodEvent::AttributeType
1382
A QTextCharFormat for the part of the preedit string specified by
1383
start and length. value contains a QVariant of type QTextFormat
1384
specifying rendering of this part of the preedit string. There
1385
should be at most one format for every part of the preedit
1386
string. If several are specified for any character in the string the
1387
behaviour is undefined. A conforming implementation has to at least
1388
honour the backgroundColor, textColor and fontUnderline properties
1392
If set, a cursor should be shown inside the preedit string at
1393
position start. If value is a QVariant of type QColor this color
1394
will be used for rendering the cursor, otherwise the color of the
1395
surrounding text will be used. There should be at most one Cursor
1396
attribute per event. If several are specified the behaviour is undefined.
1399
The variant contains a QLocale object specifying the language of a
1400
certain part of the preedit string. There should be at most one
1401
language set for every part of the preedit string. If several are
1402
specified for any character in the string the behaviour is undefined.
1405
The ruby text for a part of the preedit string. There should be at
1406
most one ruby text set for every part of the preedit string. If
1407
several are specified for any character in the string the behaviour
1414
\class QInputMethodEvent::Attribute
1415
\brief The QInputMethodEvent::Attribute class stores an input method attribute.
1419
\fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length, QVariant value)
1421
Constructs an input method attribute. \a type specifies the type
1422
of attribute, \a start and \a length the position of the
1423
attribute, and \a value the value of the attribute.
1427
Constructs an event of type QEvent::InputMethod. The
1428
attributes(), preeditString(), commitString(), replacementStart(),
1429
and replacementLength() are initialized to default values.
1431
\sa setCommitString()
1433
QInputMethodEvent::QInputMethodEvent()
1434
: QEvent(QEvent::InputMethod), replace_from(0), replace_length(0)
1439
Construcs an event of type QEvent::InputMethod. The
1440
preedit text is set to \a preeditText, the attributes to
1443
The commitString(), replacementStart(), and replacementLength()
1444
values can be set using setCommitString().
1446
\sa preeditString(), attributes()
1448
QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes)
1449
: QEvent(QEvent::InputMethod), preedit(preeditText), attrs(attributes),
1450
replace_from(0), replace_length(0)
1455
Constructs a copy of \a other.
1457
QInputMethodEvent::QInputMethodEvent(const QInputMethodEvent &other)
1458
: QEvent(QEvent::InputMethod), preedit(other.preedit), attrs(other.attrs),
1459
commit(other.commit), replace_from(other.replace_from), replace_length(other.replace_length)
1464
Sets the commit string to \a commitString.
1466
The commit string is the text that should get added to (or
1467
replace parts of) the text of the editor widget. It usually is a
1468
result of the input operations and has to be inserted to the
1469
widgets text directly before the preedit string.
1471
If the commit string should replace parts of the of the text in
1472
the editor, \a replaceLength specifies the number of
1473
characters to be replaced. \a replaceFrom specifies the position
1474
at which characters are to be replaced relative from the start of
1477
\sa commitString(), replacementStart(), replacementLength()
1479
void QInputMethodEvent::setCommitString(const QString &commitString, int replaceFrom, int replaceLength)
1481
commit = commitString;
1482
replace_from = replaceFrom;
1483
replace_length = replaceLength;
1487
\fn const QList<Attribute> &QInputMethodEvent::attributes() const
1489
Returns the list of attributes passed to the QInputMethodEvent
1490
constructor. The attributes control the visual appearance of the
1491
preedit string (the visual appearance of text outside the preedit
1492
string is controlled by the widget only).
1494
\sa preeditString(), Attribute
1498
\fn const QString &QInputMethodEvent::preeditString() const
1500
Returns the preedit text, i.e. the text before the user started
1503
\sa commitString(), attributes()
1507
\fn const QString &QInputMethodEvent::commitString() const
1509
Returns the text that should get added to (or replace parts of)
1510
the text of the editor widget. It usually is a result of the
1511
input operations and has to be inserted to the widgets text
1512
directly before the preedit string.
1514
\sa setCommitString(), preeditString(), replacementStart(), replacementLength()
1518
\fn int QInputMethodEvent::replacementStart() const
1520
Returns the position at which characters are to be replaced relative
1521
from the start of the preedit string.
1523
\sa replacementLength(), setCommitString()
1527
\fn int QInputMethodEvent::replacementLength() const
1529
Returns the number of characters to be replaced in the preedit
1532
\sa replacementStart(), setCommitString()
1537
\brief The QTabletEvent class contains parameters that describe a Tablet event.
1541
Tablet Events are generated from a Wacom tablet. Most of the time you will
1542
want to deal with events from the tablet as if they were events from a
1543
mouse; for example, you would retrieve the cursor position with x(), y(),
1544
pos(), globalX(), globalY(), and globalPos(). In some situations you may
1545
wish to retrieve the extra information provided by the tablet device
1546
driver; for example, you might want to do subpixeling with higher
1547
resolution coordinates or you may want to adjust color brightness based on
1548
pressure. QTabletEvent allows you to read the pressure(), the xTilt(), and
1549
yTilt(), as well as the type of device being used with device() (see
1550
\l{TabletDevice}). It can also give you the minimum and maximum values for
1551
each device's pressure and high resolution coordinates.
1553
A tablet event contains a special accept flag that indicates
1554
whether the receiver wants the event. You should call
1555
QTabletEvent::accept() if you handle the tablet event; otherwise
1556
it will be sent to the parent widget.
1558
The QWidget::setEnabled() function can be used to enable or
1559
disable mouse and keyboard events for a widget.
1561
The event handler QWidget::tabletEvent() receives all three types of
1562
tablet events. Qt will first send a tabletEvent then, if it is not
1563
accepted, it will send a mouse event. This allows applications that
1564
don't utilize tablets to use a tablet like a mouse, while also
1565
enabling those who want to use both tablets and mouses differently.
1570
\enum QTabletEvent::TabletDevice
1572
This enum defines what type of device is generating the event.
1574
\value NoDevice No device, or an unknown device.
1575
\value Puck A Puck (a device that is similar to a flat mouse with
1576
a transparent circle with cross-hairs).
1577
\value Stylus A Stylus.
1578
\value Airbrush An airbrush
1579
\value FourDMouse A 4D Mouse.
1580
\omitvalue XFreeEraser
1584
\enum QTabletEvent::PointerType
1586
This enum defines what type of point is generating the event.
1588
\value UnknownPointer An unknown device.
1589
\value Pen Tip end of a stylus-like device (the narrow end of the pen).
1590
\value Cursor Any puck-like device.
1591
\value Eraser Eraser end of a stylus-like device (the broad end of the pen).
1597
Construct a tablet event of the given \a type.
1599
The \a pos parameter indicates where the event occurred in the
1600
widget; \a globalPos is the corresponding position in absolute
1601
coordinates. The \a hiResGlobalPos contains a high resolution
1602
measurement of the position.
1604
\a pressure contains the pressure exerted on the \a device.
1606
\a pointerType describes the type of pen that is being used.
1608
\a xTilt and \a yTilt contain the device's degree of tilt from the
1609
x and y axes respectively.
1611
\a keyState specifies which keyboard modifiers are pressed (e.g.,
1614
The \a uniqueID parameter contains the unique ID for the current device.
1616
The \a z parameter contains the coordinate of the device on the tablet, this
1617
is usually given by a wheel on 4D mouse. If the device does not support a
1618
Z-axis, pass zero here.
1620
The \a tangentialPressure paramater contins the tangential pressure of an air
1621
brush. If the device does not support tangential pressure, pass 0 here.
1623
\a rotation contains the device's rotation in degrees. 4D mice support
1624
rotation. If the device does not support rotation, pass 0 here.
1626
\sa pos() globalPos() device() pressure() xTilt() yTilt() uniqueId(), rotation(), tangentialPressure(), z()
1629
QTabletEvent::QTabletEvent(Type type, const QPoint &pos, const QPoint &globalPos,
1630
const QPointF &hiResGlobalPos, int device, int pointerType,
1631
qreal pressure, int xTilt, int yTilt, qreal tangentialPressure,
1632
qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID)
1633
: QInputEvent(type, keyState),
1636
mHiResGlobalPos(hiResGlobalPos),
1638
mPointerType(pointerType),
1643
mTangential(tangentialPressure),
1653
QTabletEvent::~QTabletEvent()
1658
\fn TabletDevices QTabletEvent::device() const
1660
Returns the type of device that generated the event.
1662
This is useful if you want to know which end of a pen was used
1663
to draw on the tablet.
1669
\fn PointerType QTabletEvent::pointerType() const
1671
Returns the type of point that generated the event.
1675
\fn qreal QTabletEvent::tangentialPressure() const
1677
Returns the tangential pressure for the device. This is typically given by a finger
1678
wheel on an airbrush tool. The range is from -1.0 to 1.0. 0.0 indicates a
1679
neutral position. Current airbrushes can only move in the positive
1680
direction from the neutrual position. If the device does not support
1681
tangential pressure, this value is always 0.0.
1687
\fn qreal QTabletEvent::rotation() const
1689
Returns the rotation of the current device in degress. This is usually
1690
given by a 4D Mouse. If the device doesn't support rotation this value is
1696
\fn qreal QTabletEvent::pressure() const
1698
Returns the pressure for the device. 0.0 indicates that the stylus is not
1699
on the tablet, 1.0 indicates the maximum amount of pressure for the stylus.
1701
\sa tangentialPressure()
1705
\fn int QTabletEvent::xTilt() const
1707
Returns the angle between the device (a pen, for example) and the
1708
perpendicular in the direction of the x axis.
1709
Positive values are towards the tablet's physical right. The angle
1710
is in the range -60 to +60 degrees.
1712
\img qtabletevent-tilt.png
1718
\fn int QTabletEvent::yTilt() const
1720
Returns the angle between the device (a pen, for example) and the
1721
perpendicular in the direction of the y axis.
1722
Positive values are towards the bottom of the tablet. The angle is
1723
within the range -60 to +60 degrees.
1729
\fn const QPoint &QTabletEvent::pos() const
1731
Returns the position of the device, relative to the widget that
1734
If you move widgets around in response to mouse events, use
1735
globalPos() instead of this function.
1737
\sa x() y() globalPos()
1741
\fn int QTabletEvent::x() const
1743
Returns the x position of the device, relative to the widget that
1750
\fn int QTabletEvent::y() const
1752
Returns the y position of the device, relative to the widget that
1759
\fn int QTabletEvent::z() const
1761
Returns the z position of the device. Typically this is represented by a
1762
wheel on a 4D Mouse. If the device does not support a Z-axis, this value is
1763
always zero. This is <em>not</em> the same as pressure.
1769
\fn const QPoint &QTabletEvent::globalPos() const
1771
Returns the global position of the device \e{at the time of the
1772
event}. This is important on asynchronous windows systems like X11;
1773
whenever you move your widgets around in response to mouse events,
1774
globalPos() can differ significantly from the current position
1777
\sa globalX() globalY() hiResGlobalPos()
1781
\fn int QTabletEvent::globalX() const
1783
Returns the global x position of the mouse pointer at the time of
1786
\sa globalY() globalPos() hiResGlobalX()
1790
\fn int QTabletEvent::globalY() const
1792
Returns the global y position of the tablet device at the time of
1795
\sa globalX() globalPos() hiResGlobalY()
1799
\fn qint64 QTabletEvent::uniqueId() const
1801
Returns a unique ID for the current device, making it possible
1802
to differentiate between multiple devices being used at the same
1805
Values for the same device may vary from OS to OS.
1807
It is possible to generate a unique ID for any Wacom device.
1811
\fn const QPointF &QTabletEvent::hiResGlobalPos() const
1813
The high precision coordinates delivered from the tablet expressed.
1814
Sub pixeling information is in the fractional part of the QPointF.
1816
\sa globalPos() hiResGlobalX() hiResGlobalY()
1820
\fn qreal &QTabletEvent::hiResGlobalX() const
1822
The high precision x position of the tablet device.
1826
\fn qreal &QTabletEvent::hiResGlobalY() const
1828
The high precision y position of the tablet device.
1832
Creates a QDragMoveEvent of the required \a type indicating
1833
that the mouse is at position \a pos given within a widget.
1835
The mouse and keyboard states are specified by \a buttons and
1836
\a modifiers, and the \a actions describe the types of drag
1837
and drop operation that are possible.
1838
The drag data is passed as MIME-encoded information in \a data.
1840
\warning Do not attempt to create a QDragMoveEvent yourself.
1841
These objects rely on Qt's internal state.
1843
QDragMoveEvent::QDragMoveEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
1844
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
1845
: QDropEvent(pos, actions, data, buttons, modifiers, type)
1846
, rect(pos, QSize(1, 1))
1852
QDragMoveEvent::~QDragMoveEvent()
1857
\fn void QDragMoveEvent::accept(bool y)
1859
Calls setAccepted(\a y) instead.
1863
\fn void QDragMoveEvent::accept(const QRect &rectangle)
1865
The same as accept(), but also notifies that future moves will
1866
also be acceptable if they remain within the \a rectangle
1867
given on the widget. This can improve performance, but may
1868
also be ignored by the underlying system.
1870
If the rectangle is empty, drag move events will be sent
1871
continuously. This is useful if the source is scrolling in a
1876
\fn void QDragMoveEvent::accept()
1880
Calls QDropEvent::accept().
1884
\fn void QDragMoveEvent::ignore()
1888
Calls QDropEvent::ignore().
1892
\fn void QDragMoveEvent::ignore(const QRect &rectangle)
1894
The opposite of the accept(const QRect&) function.
1895
Moves within the \a rectangle are not acceptable, and will be
1900
\fn QRect QDragMoveEvent::answerRect() const
1902
Returns the rectangle in the widget where the drop will occur if accepted.
1903
You can use this information to restrict drops to certain places on the
1911
\ingroup draganddrop
1913
\brief The QDropEvent class provides an event which is sent when a
1914
drag and drop action is completed.
1916
When a widget \l{QWidget::setAcceptDrops()}{accepts drop events}, it will
1917
receive this event if it has accepted the most recent QDragEnterEvent or
1918
QDragMoveEvent sent to it.
1920
The drop event contains a proposed action, available from proposedAction(), for
1921
the widget to either accept or ignore. If the action can be handled by the
1922
widget, you should call the acceptProposedAction() function. Since the
1923
proposed action can be a combination of \l Qt::DropAction values, it may be
1924
useful to either select one of these values as a default action or ask
1925
the user to select their preferred action. If the required drop action is
1926
different to the proposed action, you can call setDropAction() instead of
1927
acceptProposedAction() to complete the drop operation.
1929
The mimeData() function provides the data dropped on the widget in a QMimeData
1930
object. This contains information about the MIME type of the data in addition to
1933
\sa QMimeData, QDrag, {Drag and Drop}
1937
\fn const QMimeData *QDropEvent::mimeData() const
1939
Returns the data that was dropped on the widget and its associated MIME
1944
Constructs a drop event of a certain \a type corresponding to a
1945
drop at the point specified by \a pos in the destination widget's
1948
The \a actions indicate which types of drag and drop operation can
1949
be performed, and the drag data is stored as MIME-encoded data in \a data.
1951
The states of the mouse buttons and keyboard modifiers at the time of
1952
the drop are specified by \a buttons and \a modifiers.
1953
*/ // ### pos is in which coordinate system?
1954
QDropEvent::QDropEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
1955
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
1956
: QEvent(type), p(pos), mouseState(buttons),
1957
modState(modifiers), act(actions),
1958
drop_action(Qt::CopyAction),
1961
default_action = QDragManager::self()->defaultAction(act, modifiers);
1966
QDropEvent::~QDropEvent()
1972
Returns a byte array containing the drag's data, in \a format.
1974
data() normally needs to get the data from the drag source, which
1975
is potentially very slow, so it's advisable to call this function
1976
only if you're sure that you will need the data in that
1977
particular \a format.
1979
The resulting data will have a size of 0 if the format was not
1982
\sa format() QByteArray::size()
1985
QByteArray QDropEvent::encodedData(const char *format) const
1987
return mdata->data(QLatin1String(format));
1992
Returns a string describing one of the available data types for
1993
this drag. Common examples are "text/plain" and "image/gif".
1994
If \a n is less than zero or greater than the number of available
1995
data types, format() returns 0.
1997
This function is provided mainly for debugging. Most drop targets
1998
will use provides().
2000
\sa data() provides()
2003
const char* QDropEvent::format(int n) const
2005
if (fmts.isEmpty()) {
2006
QStringList formats = mdata->formats();
2007
for (int i = 0; i < formats.size(); ++i)
2008
fmts.append(formats.at(i).toLatin1());
2010
if (n < 0 || n >= fmts.size())
2012
return fmts.at(n).constData();
2017
Returns true if this event provides format \a mimeType; otherwise
2023
bool QDropEvent::provides(const char *mimeType) const
2025
return mdata->formats().contains(QLatin1String(mimeType));
2029
If the source of the drag operation is a widget in this
2030
application, this function returns that source; otherwise it
2031
returns 0. The source of the operation is the first parameter to
2032
the QDrag object used instantiate the drag.
2034
This is useful if your widget needs special behavior when dragging
2039
QWidget* QDropEvent::source() const
2041
QDragManager *manager = QDragManager::self();
2042
return manager ? manager->source() : 0;
2046
void QDropEvent::setDropAction(Qt::DropAction action)
2048
if (!(action & act))
2049
action = Qt::CopyAction;
2050
drop_action = action;
2054
\fn const QPoint& QDropEvent::pos() const
2056
Returns the position where the drop was made.
2060
\fn Qt::MouseButtons QDropEvent::mouseButtons() const
2062
Returns the mouse buttons that are pressed..
2066
\fn Qt::KeyboardModifiers QDropEvent::keyboardModifiers() const
2068
Returns the modifier keys that are pressed.
2072
\fn void QDropEvent::accept()
2077
\fn void QDropEvent::accept(bool accept)
2079
Call setAccepted(\a accept) instead.
2083
\fn void QDropEvent::acceptAction(bool accept = true)
2085
Call this to indicate that the action described by action() is
2086
accepted (i.e. if \a accept is true, which is the default), not merely
2087
the default copy action. If you call acceptAction(true), there is
2088
no need to also call accept(true).
2092
\enum QDropEvent::Action
2095
When a drag and drop action is completed, the target is expected
2096
to perform an action on the data provided by the source. This
2097
will be one of the following:
2099
\value Copy The default action. The source simply uses the data
2100
provided in the operation.
2101
\value Link The source should somehow create a link to the
2102
location specified by the data.
2103
\value Move The source should somehow move the object from the
2104
location specified by the data to a new location.
2105
\value Private The target has special knowledge of the MIME type,
2106
which the source should respond to in a similar way to
2108
\value UserAction The source and target can co-operate using
2109
special actions. This feature is not currently
2112
The Link and Move actions only makes sense if the data is a
2113
reference, for example, text/uri-list file lists (see QUriDrag).
2117
\fn void QDropEvent::setDropAction(Qt::DropAction action)
2119
Sets the \a action to be performed on the data by the target.
2120
Use this to override the \l{proposedAction()}{proposed action}
2121
with one of the \l{possibleActions()}{possible actions}.
2123
If you set a drop action that is not one of the possible actions, the
2124
drag and drop operation will default to a copy operation.
2130
\fn Qt::DropAction QDropEvent::dropAction() const
2132
Returns the action that the target is expected to perform on the
2133
data. If your application understands the action and can
2134
process the supplied data, call acceptAction(); if your
2135
application can process the supplied data but can only perform the
2136
Copy action, call accept().
2142
\fn Qt::DropActions QDropEvent::possibleActions() const
2144
Returns an OR-combination of possible drop actions.
2150
\fn Qt::DropAction QDropEvent::proposedAction() const
2152
Returns the proposed drop action.
2158
\fn void QDropEvent::acceptProposedAction()
2160
Sets the drop action to be the proposed action.
2162
\sa setDropAction(), proposedAction(), accept()
2167
Use dropAction() instead.
2169
The table below shows the correspondance between the return type
2170
of action() and the return type of dropAction().
2173
\header \i Old enum value \i New enum value
2174
\row \i QDropEvent::Copy \i Qt::CopyAction
2175
\row \i QDropEvent::Move \i Qt::MoveAction
2176
\row \i QDropEvent::Link \i Qt::LinkAction
2177
\row \i other \i Qt::CopyAction
2181
QT3_SUPPORT QDropEvent::Action QDropEvent::action() const
2183
switch(drop_action) {
2184
case Qt::CopyAction:
2186
case Qt::MoveAction:
2188
case Qt::LinkAction:
2197
\fn void QDropEvent::setPoint(const QPoint &point)
2200
Sets the drop to happen at the given \a point. You do not normally
2201
need to use this as it will be set internally before your widget
2202
receives the drop event.
2203
*/ // ### here too - what coordinate system?
2207
\class QDragEnterEvent
2208
\brief The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action enters it.
2211
\ingroup draganddrop
2213
This event is always immediately followed by a QDragMoveEvent, so
2214
you only need to respond to one or the other event. This class
2215
inherits most of its functionality from QDragMoveEvent, which in
2216
turn inherits most of its functionality from QDropEvent.
2218
\sa QDragLeaveEvent, QDragMoveEvent, QDropEvent
2222
Constructs a QDragEnterEvent that represents a drag entering a
2223
widget at the given \a point with mouse and keyboard states specified by
2224
\a buttons and \a modifiers.
2226
The drag data is passed as MIME-encoded information in \a data, and the
2227
specified \a actions describe the possible types of drag and drop
2228
operation that can be performed.
2230
\warning Do not create a QDragEnterEvent yourself since these
2231
objects rely on Qt's internal state.
2233
QDragEnterEvent::QDragEnterEvent(const QPoint& point, Qt::DropActions actions, const QMimeData *data,
2234
Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
2235
: QDragMoveEvent(point, actions, data, buttons, modifiers, DragEnter)
2240
QDragEnterEvent::~QDragEnterEvent()
2245
Constructs a drag response event containing the \a accepted value,
2246
indicating whether the drag and drop operation was accepted by the
2249
QDragResponseEvent::QDragResponseEvent(bool accepted)
2250
: QEvent(DragResponse), a(accepted)
2255
QDragResponseEvent::~QDragResponseEvent()
2260
\class QDragMoveEvent
2261
\brief The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress.
2264
\ingroup draganddrop
2266
When a widget \l{QWidget::setAcceptDrops()}{accepts drop events},
2267
it will receive this event repeatedly while the drag is within
2268
the widget's boundaries. The widget should examine the event to
2269
see what kind of data it
2270
\l{QDragMoveEvent::provides()}{provides}, and call the accept()
2271
function to accept the drop if appropriate.
2273
The rectangle supplied by the answerRect() function can be used to restrict
2274
drops to certain parts of the widget. For example, we can check whether the
2275
rectangle intersects with the geometry of a certain child widget and only
2276
call \l{QDropEvent::acceptProposedAction()}{acceptProposedAction()} if that
2279
Note that this class inherits most of its functionality from
2282
\sa QDragEnterEvent, QDragLeaveEvent, QDropEvent
2286
\class QDragLeaveEvent
2287
\brief The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leaves it.
2290
\ingroup draganddrop
2292
This event is always preceded by a QDragEnterEvent and a series
2293
of \l{QDragMoveEvent}s. It is not sent if a QDropEvent is sent
2296
\sa QDragEnterEvent, QDragMoveEvent, QDropEvent
2300
Constructs a QDragLeaveEvent.
2302
\warning Do not create a QDragLeaveEvent yourself since these
2303
objects rely on Qt's internal state.
2305
QDragLeaveEvent::QDragLeaveEvent()
2311
QDragLeaveEvent::~QDragLeaveEvent()
2317
\brief The QHelpEvent class provides an event that is used to request helpful information
2318
about a particular point in a widget.
2323
This event can be intercepted in applications to provide tooltips
2324
or "What's This?" help for custom widgets. The type() can be
2325
either QEvent::ToolTip or QEvent::WhatsThis.
2327
\sa QToolTip, QWhatsThis, QStatusTipEvent, QWhatsThisClickedEvent
2331
Constructs a help event with the given \a type corresponding to the
2332
widget-relative position specified by \a pos and the global position
2333
specified by \a globalPos.
2335
\a type must be either QEvent::ToolTip or QEvent::WhatsThis.
2337
\sa pos(), globalPos()
2339
QHelpEvent::QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos)
2340
: QEvent(type), p(pos), gp(globalPos)
2344
\fn int QHelpEvent::x() const
2348
\sa y(), pos(), globalPos()
2352
\fn int QHelpEvent::y() const
2356
\sa x(), pos(), globalPos()
2360
\fn int QHelpEvent::globalX() const
2362
Same as globalPos().x().
2364
\sa x(), globalY(), globalPos()
2368
\fn int QHelpEvent::globalY() const
2370
Same as globalPos().y().
2372
\sa y(), globalX(), globalPos()
2376
\fn const QPoint &QHelpEvent::pos() const
2378
Returns the mouse cursor position when the event was generated,
2379
relative to the widget to which the event is dispatched.
2381
\sa globalPos(), x(), y()
2385
\fn const QPoint &QHelpEvent::globalPos() const
2387
Returns the mouse cursor position when the event was generated
2388
in global coordinates.
2390
\sa pos(), globalX(), globalY()
2395
QHelpEvent::~QHelpEvent()
2400
\class QStatusTipEvent
2401
\brief The QStatusTipEvent class provides an event that is used to show messages in a status bar.
2406
Status tips can be set on a widget using QWidget::setStatusTip().
2407
They are shown in the status bar when the mouse cursor enters the
2408
widget. Status tips can also be set on actions using
2409
QAction::setStatusTip(), and they are supported for the item view
2410
classes through Qt::StatusTipRole.
2412
\sa QStatusBar, QHelpEvent, QWhatsThisClickedEvent
2416
Constructs a status tip event with text specified by \a tip.
2420
QStatusTipEvent::QStatusTipEvent(const QString &tip)
2421
: QEvent(StatusTip), s(tip)
2426
QStatusTipEvent::~QStatusTipEvent()
2431
\fn QString QStatusTipEvent::tip() const
2433
Returns the message to show in the status bar.
2435
\sa QStatusBar::showMessage()
2439
\class QWhatsThisClickedEvent
2440
\brief The QWhatsThisClickedEvent class provides an event that
2441
can be used to handle hyperlinks in a "What's This?" text.
2446
\sa QWhatsThis, QHelpEvent, QStatusTipEvent
2450
Constructs an event containing a URL specified by \a href when a link
2451
is clicked in a "What's This?" message.
2455
QWhatsThisClickedEvent::QWhatsThisClickedEvent(const QString &href)
2456
: QEvent(WhatsThisClicked), s(href)
2461
QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
2466
\fn QString QWhatsThisClickedEvent::href() const
2468
Returns the URL that was clicked by the user in the "What's
2474
\brief The QActionEvent class provides an event that is generated
2475
when a QAction is added, removed, or changed.
2479
Actions can be added to widgets using QWidget::addAction(). This
2480
generates an \l ActionAdded event, which you can handle to provide
2481
custom behavior. For example, QToolBar reimplements
2482
QWidget::actionEvent() to create \l{QToolButton}s for the
2485
\sa QAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions()
2489
Constructs an action event. The \a type can be \l ActionChanged,
2490
\l ActionAdded, or \l ActionRemoved.
2492
\a action is the action that is changed, added, or removed. If \a
2493
type is ActionAdded, the action is to be inserted before the
2494
action \a before. If \a before is 0, the action is appended.
2496
QActionEvent::QActionEvent(int type, QAction *action, QAction *before)
2497
: QEvent(static_cast<QEvent::Type>(type)), act(action), bef(before)
2502
QActionEvent::~QActionEvent()
2507
\fn QAction *QActionEvent::action() const
2509
Returns the action that is changed, added, or removed.
2515
\fn QAction *QActionEvent::before() const
2517
If type() is \l ActionAdded, returns the action that should
2518
appear before action(). If this function returns 0, the action
2519
should be appended to already existing actions on the same
2522
\sa action(), QWidget::actions()
2527
\brief The QHideEvent class provides an event which is sent after a widget is hidden.
2531
This event is sent just before QWidget::hide() returns, and also
2532
when a top-level window has been hidden (iconified) by the user.
2534
If spontaneous() is true, the event originated outside the
2535
application. In this case, the user hid the window using the
2536
window manager controls, either by iconifying the window or by
2537
switching to another virtual desktop where the window isn't
2538
visible. The window will become hidden but not withdrawn. If the
2539
window was iconified, QWidget::isMinimized() returns true.
2545
Constructs a QHideEvent.
2547
QHideEvent::QHideEvent()
2553
QHideEvent::~QHideEvent()
2559
\brief The QShowEvent class provides an event that is sent when a widget is shown.
2563
There are two kinds of show events: show events caused by the
2564
window system (spontaneous), and internal show events. Spontaneous
2565
show events are sent just after the window system shows the
2566
window; they are also sent when a top-level window is redisplayed
2567
after being iconified. Internal show events are delivered just
2568
before the widget becomes visible.
2574
Constructs a QShowEvent.
2576
QShowEvent::QShowEvent()
2582
QShowEvent::~QShowEvent()
2587
\fn QByteArray QDropEvent::data(const char* f) const
2591
The encoded data is in \a f.
2592
Use QDropEvent::encodedData().
2596
\class QFileOpenEvent
2597
\brief The QFileOpenEvent class provides an event that will be
2598
sent when there is a request to open a file.
2602
File open events will be sent to the QApplication::instance()
2603
when the operating system requests that a file be opened. This is
2604
a high-level event that can be caused by different user actions
2605
depending on the user's desktop environment; for example, double
2606
clicking on an file icon in the Finder on Mac OS X.
2608
This event is only used to notify the application of a request.
2609
It may be safely ignored.
2615
Constructs a file open event for the given \a file.
2617
QFileOpenEvent::QFileOpenEvent(const QString &file)
2618
: QEvent(FileOpen), f(file)
2623
QFileOpenEvent::~QFileOpenEvent()
2628
\fn QString QFileOpenEvent::file() const
2630
Returns the file that is being opened.
2635
\class QToolBarChangeEvent
2636
\brief The QToolBarChangeEvent class provides an event that is
2637
sent whenever a the toolbar button is clicked on Mac OS X.
2641
The QToolBarChangeEvent is sent when the toolbar button is clicked. On Mac
2642
OS X, this is the long oblong button on the right side of the window
2643
titlebar. The default implementation is to toggle the appearance (hidden or
2644
shown) of the associated toolbars for the window.
2650
Construct a QToolBarChangeEvent given the current button state in \a state.
2652
QToolBarChangeEvent::QToolBarChangeEvent(bool t)
2653
: QEvent(ToolBarChange), tog(t)
2658
QToolBarChangeEvent::~QToolBarChangeEvent()
2663
\fn bool QToolBarChangeEvent::toggle() const
2668
\fn Qt::ButtonState QToolBarChangeEvent::state() const
2670
Returns the keyboard modifier flags at the time of the event.
2672
The returned value is a selection of the following values,
2673
combined using the OR operator:
2674
Qt::ShiftButton, Qt::ControlButton, Qt::MetaButton, and Qt::AltButton.
2677
QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous)
2678
: QEvent(Shortcut), sequence(key), ambig(ambiguous), sid(id)
2681
QShortcutEvent::~QShortcutEvent()
2685
#ifndef QT_NO_DEBUG_STREAM
2686
QDebug operator<<(QDebug dbg, const QEvent *e) {
2687
#ifndef Q_BROKEN_DEBUG_STREAM
2688
// More useful event output could be added here
2690
return dbg << "QEvent(this = 0x0)";
2692
switch (e->type()) {
2696
case QEvent::MouseButtonPress:
2697
case QEvent::MouseMove:
2698
case QEvent::MouseButtonRelease:
2699
case QEvent::MouseButtonDblClick:
2701
const QMouseEvent *me = static_cast<const QMouseEvent*>(e);
2702
switch(me->type()) {
2703
case QEvent::MouseButtonPress:
2704
n = "MouseButtonPress";
2706
case QEvent::MouseMove:
2709
case QEvent::MouseButtonRelease:
2710
n = "MouseButtonRelease";
2712
case QEvent::MouseButtonDblClick:
2714
n = "MouseButtonDblClick";
2717
dbg.nospace() << "QMouseEvent(" << n
2718
<< ", " << me->button()
2719
<< ", " << hex << (int)me->buttons()
2720
<< ", " << hex << (int)me->modifiers()
2724
case QEvent::ToolTip:
2727
case QEvent::WindowActivate:
2728
n = "WindowActivate";
2730
case QEvent::WindowDeactivate:
2731
n = "WindowDeactivate";
2733
case QEvent::ActivationChange:
2734
n = "ActivationChange";
2736
#ifndef QT_NO_WHEELEVENT
2741
case QEvent::KeyPress:
2742
case QEvent::KeyRelease:
2743
case QEvent::ShortcutOverride:
2745
const QKeyEvent *ke = static_cast<const QKeyEvent*>(e);
2746
switch(ke->type()) {
2747
case QEvent::ShortcutOverride:
2748
n = "ShortcutOverride";
2750
case QEvent::KeyRelease:
2753
case QEvent::KeyPress:
2758
dbg.nospace() << "QKeyEvent(" << n
2759
<< ", " << hex << ke->key()
2760
<< ", " << hex << (int)ke->modifiers()
2761
<< ", \"" << ke->text()
2762
<< "\", " << ke->isAutoRepeat()
2763
<< ", " << ke->count()
2767
case QEvent::FocusIn:
2770
case QEvent::FocusOut:
2785
case QEvent::Resize:
2788
case QEvent::Create:
2791
case QEvent::Destroy:
2800
case QEvent::FileOpen:
2804
dbg.nospace() << "QEvent(" << (const void *)e << ", type = " << e->type() << ')';
2808
dbg.nospace() << 'Q' << n << "Event(" << (const void *)e << ')';
2811
qWarning("This compiler doesn't support streaming QEvent to QDebug");
2821
\class QClipboardEvent
2824
\brief The QClipboardEvent class provides the parameters used in a clipboard event.
2826
This class is for internal use only, and exists to aid the clipboard on various
2827
platforms to get all the information it needs. Use QEvent::Clipboard instead.
2830
QClipboardEvent::QClipboardEvent(QEventPrivate *data)
2831
: QEvent(QEvent::Clipboard)
2834
QClipboardEvent::~QClipboardEvent()
2839
\class QShortcutEvent
2840
\brief The QShortcutEvent class provides an event which is generated when
2841
the user presses a key combination.
2845
Normally you don't need to use this class directly; QShortcut
2846
provides a higher-level interface to handle shortcut keys.
2852
\fn QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous = false)
2854
Constructs a shortcut event for the given \a key press,
2855
associated with the QShortcut ID \a id.
2857
\a ambiguous specifies whether there is more than one QShortcut
2858
for the same key sequence.
2862
\fn QShortcutEvent::~QShortcutEvent()
2864
Destroys the event object.
2868
\fn const QKeySequence &QShortcutEvent::key()
2870
Returns the key sequence that triggered the event.
2874
\fn int QShortcutEvent::shortcutId()
2876
Returns the ID of the QShortcut object for which this event was
2883
\fn bool QShortcutEvent::isAmbiguous()
2885
Returns true if the key sequence that triggered the event is
2888
\sa QShortcut::activatedAmbiguously()
2892
\class QWindowStateChangeEvent
2895
\brief The QWindowStateChangeEvent class provides the window state before a
2896
window state change.
2899
/*! \fn Qt::WindowStates QWindowStateChangeEvent::oldState() const
2901
Returns the state of the window before the change.
2906
QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s)
2907
: QEvent(WindowStateChange), ostate(s)
2913
QWindowStateChangeEvent::~QWindowStateChangeEvent()