📄 qevent.cpp
字号:
{ g = QCursor::pos(); mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask); modState = Qt::KeyboardModifiers(state & (int)Qt::KeyButtonMask);}#endif/*! Constructs a wheel event object. The \a pos provides the location of the mouse cursor within the widget. The position in global coordinates is specified by \a globalPos. \a delta contains the rotation distance, \a modifiers holds the keyboard modifier flags at the time of the event, and \a orient holds the wheel's orientation. \sa pos() globalPos() delta() state()*/QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient) : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), d(delta), mouseState(buttons), o(orient){}#ifdef QT3_SUPPORT/*! Use one of the other constructors instead.*/QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, int state, Qt::Orientation orient) : QInputEvent(Wheel), p(pos), g(globalPos), d(delta), o(orient){ mouseState = Qt::MouseButtons(state & Qt::MouseButtonMask); modState = Qt::KeyboardModifiers(state & (int) Qt::KeyButtonMask);}#endif#endif // QT_NO_WHEELEVENT/*! \fn int QWheelEvent::delta() const Returns the distance that the wheel is rotated, in eights of a degree. A positive value indicates that the wheel was rotated forwards away from the user; a negative value indicates that the wheel was rotated backwards toward the user. Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of 120 (== 15 * 8). Example: \code void MyWidget::wheelEvent(QWheelEvent *event) { int numDegrees = event->delta() / 8; int numSteps = numDegrees / 15; if (event->orientation() == Qt::Horizontal) { scrollHorizontally(numSteps); } else { scrollVertically(numSteps); } } \endcode*//*! \fn const QPoint &QWheelEvent::pos() const Returns the position of the mouse cursor relative to the widget that received the event. If you move your widgets around in response to mouse events, use globalPos() instead of this function. \sa x() y() globalPos()*//*! \fn int QWheelEvent::x() const Returns the x position of the mouse cursor, relative to the widget that received the event. \sa y() pos()*//*! \fn int QWheelEvent::y() const Returns the y position of the mouse cursor, relative to the widget that received the event. \sa x() pos()*//*! \fn const QPoint &QWheelEvent::globalPos() const Returns the global position of the mouse pointer \e{at the time of the event}. This is important on asynchronous window systems such as X11; whenever you move your widgets around in response to mouse events, globalPos() can differ a lot from the current cursor position returned by QCursor::pos(). \sa globalX() globalY()*//*! \fn int QWheelEvent::globalX() const Returns the global x position of the mouse cursor at the time of the event. \sa globalY() globalPos()*//*! \fn int QWheelEvent::globalY() const Returns the global y position of the mouse cursor at the time of the event. \sa globalX() globalPos()*//*! \obsolete \fn Qt::ButtonState QWheelEvent::state() const Returns the keyboard modifier flags at the time of the event. The returned value is a selection of the following values, combined using the OR operator: Qt::ShiftButton, Qt::ControlButton, and Qt::AltButton.*//*! \class QKeyEvent \brief The QKeyEvent class contains describes a key event. \ingroup events Key events are sent to the widget with keyboard input focus when keys are pressed or released. A key event contains a special accept flag that indicates whether the receiver will handle the key event. You should call ignore() if the key press or release event is not handled by your widget. A key event is propagated up the parent widget chain until a widget accepts it with accept() or an event filter consumes it. Key events for multimedia keys are ignored by default. You should call accept() if your widget handles those events. The QWidget::setEnable() function can be used to enable or disable mouse and keyboard events for a widget. The event handlers QWidget::keyPressEvent() and QWidget::keyReleaseEvent() receive key events. \sa QFocusEvent, QWidget::grabKeyboard()*//*! Constructs a key event object. The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease, or QEvent::ShortcutOverride. If \a key is 0, the event is not a result of a known key; for example, it may be the result of a compose sequence or keyboard macro. The \a modifiers holds the keyboard modifiers, and the given \a text is the Unicode text that the key generated. If \a autorep is true, isAutoRepeat() will be true. \a count is the number of keys involved in the event.*/QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text, bool autorep, ushort count) : QInputEvent(type, modifiers), txt(text), k(key), c(count), autor(autorep){}/*! \internal*/QKeyEvent::~QKeyEvent(){}/*! \fn int QKeyEvent::key() const Returns the code of the key that was pressed or released. See \l Qt::Key for the list of keyboard codes. These codes are independent of the underlying window system. Note that this function does not distinguish between capital and non-capital letters, use the text() function (returning the Unicode text the key generated) for this purpose. A value of either 0 or Qt::Key_unknown means that the event is not the result of a known key; for example, it may be the result of a compose sequence, a keyboard macro, or due to key event compression. \sa Qt::WA_KeyCompression*//*! \fn QString QKeyEvent::text() const Returns the Unicode text that this key generated. The text returned can be an empty string in cases where modifier keys, such as Shift, Control, Alt, and Meta, are being pressed or released. In such cases key() will contain a valid value. \sa Qt::WA_KeyCompression*//*! Returns the keyboard modifier flags that existed immediately after the event occurred. \warning This function cannot always be trusted. The user can confuse it by pressing both \key{Shift} keys simulatenously and releasing one of them, for example. \sa QApplication::keyboardModifiers()*///###### We must check with XGetModifierMappingQt::KeyboardModifiers QKeyEvent::modifiers() const{ if (key() == Qt::Key_Shift) return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ShiftModifier); if (key() == Qt::Key_Control) return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ControlModifier); if (key() == Qt::Key_Alt) return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::AltModifier); if (key() == Qt::Key_Meta) return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::MetaModifier); return QInputEvent::modifiers();}/*! \fn bool QKeyEvent::isAutoRepeat() const Returns true if this event comes from an auto-repeating key; returns false if it comes from an initial key press. Note that if the event is a multiple-key compressed event that is partly due to auto-repeat, this function could return either true or false indeterminately.*//*! \fn int QKeyEvent::count() const Returns the number of keys involved in this event. If text() is not empty, this is simply the length of the string. \sa Qt::WA_KeyCompression*/#ifdef QT3_SUPPORT/*! \fn QKeyEvent::QKeyEvent(Type type, int key, int ascii, int modifiers, const QString &text, bool autorep, ushort count) Use one of the other constructors instead.*//*! \fn int QKeyEvent::ascii() const Use text() instead.*//*! \fn Qt::ButtonState QKeyEvent::state() const Use QInputEvent::modifiers() instead.*//*! \fn Qt::ButtonState QKeyEvent::stateAfter() const Use modifiers() instead.*/#endif/*! \class QFocusEvent \brief The QFocusEvent class contains event parameters for widget focus events. \ingroup events Focus events are sent to widgets when the keyboard input focus changes. Focus events occur due to mouse actions, key presses (such as \gui{Tab} or \gui{Backtab}), the window system, popup menus, keyboard shortcuts, or other application-specific reasons. The reason for a particular focus event is returned by reason() in the appropriate event handler. The event handlers QWidget::focusInEvent() and QWidget::focusOutEvent() receive focus events. \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus}*//*! Constructs a focus event object. The \a type parameter must be either QEvent::FocusIn or QEvent::FocusOut. The \a reason describes the cause of the change in focus.*/QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason) : QEvent(type), m_reason(reason){}/*! \internal*/QFocusEvent::~QFocusEvent(){}/*! Returns the reason for this focus event. */Qt::FocusReason QFocusEvent::reason(){ return m_reason;}/*! \fn bool QFocusEvent::gotFocus() const Returns true if type() is QEVent::FocusIn; otherwise returns false.*//*! \fn bool QFocusEvent::lostFocus() const Returns true if type() is QEVent::FocusOut; otherwise returns false.*/#ifdef QT3_SUPPORT/*! \enum QFocusEvent::Reason \compat Use Qt::FocusReason instead. \value Mouse Same as Qt::MouseFocusReason. \value Tab Same as Qt::TabFocusReason. \value Backtab Same as Qt::BacktabFocusReason. \value MenuBar Same as Qt::MenuBarFocusReason. \value ActiveWindow Same as Qt::ActiveWindowFocusReason \value Other Same as Qt::OtherFocusReason \value Popup Same as Qt::PopupFocusReason \value Shortcut Same as Qt::ShortcutFocusReason*/#endif/*! \class QPaintEvent \brief The QPaintEvent class contains event parameters for paint events. \ingroup events Paint events are sent to widgets that need to update themselves, for instance when part of a widget is exposed because a covering widget was moved. The event contains a region() that needs to be updated, and a rect() that is the bounding rectangle of that region. Both are provided because many widgets can't make much use of region(), and rect() can be much faster than region().boundingRect(). Painting is clipped to region() during the processing of a paint event. \sa QPainter, QWidget::update(), QWidget::repaint(), QWidget::paintEvent()*//*! \fn bool QPaintEvent::erased() const \compat Returns true if the paint event region (or rectangle) has been erased with the widget's background; otherwise returns false. Qt 4 \e always erases regions that require painting. The exception to this rule is if the widget sets the Qt::WA_OpaquePaintEvent or Qt::WA_NoSystemBackground attributes. If either one of those attributes is set \e and the window system does not make use of subwidget alpha composition (currently X11 and Windows, but this may change), then the region is not erased.*//*! \fn void QPaintEvent::setErased(bool b) { m_erased = b; } \internal*//*! Constructs a paint event object with the region that needs to be updated. The region is specified by \a paintRegion.*/QPaintEvent::QPaintEvent(const QRegion& paintRegion) : QEvent(Paint), m_rect(paintRegion.boundingRect()), m_region(paintRegion), m_erased(false){}/*! Constructs a paint event object with the rectangle that needs to be updated. The region is specified by \a paintRect.*/QPaintEvent::QPaintEvent(const QRect &paintRect) : QEvent(Paint), m_rect(paintRect),m_region(paintRect), m_erased(false){}#ifdef QT3_SUPPORT /*! Constructs a paint event object with both a \a paintRegion and a \a paintRect, both of which represent the area of the widget that needs to be updated.*/QPaintEvent::QPaintEvent(const QRegion &paintRegion, const QRect &paintRect) : QEvent(Paint), m_rect(paintRect), m_region(paintRegion), m_erased(false){}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -