(1)先给出 Qt 里事件类的继承关系 :
++以及 :
++由于太多的事件类,无法全部学习,在有限的时间里,只能老师讲了哪个 ,就先学习哪个。接着依次给出各个事件的定义与简单的测试。
(2)QPaintEvent, 重绘组件事件,多种原因,可导致需要重绘组件,比如最小化了后,又显示了,等 :
/*
The QPaintEvent class contains event parameters for paint events.
Detailed Description:
绘画事件被发送给需要更新自己的小部件,例如当一个覆盖小部件移动时,某个小部件的一部分暴露出来。
该事件包含一个需要更新的`region()以及一个`rect(),后者是该区域的边界矩形。
提供这两个是因为许多小部件无法充分发挥`region()的效用,
而`rect()、的获取速度通常比`region().boundingRect()、快得多。
Automatic Clipping :自动裁剪
在处理画图事件时,绘画会被裁剪为 region()。
这一裁剪操作由Qt的画图系统执行,且与可能应用于在画图设备上绘图的OPainter的任何裁剪无关。
因此,新创建的QPainter通过QPainter:clipRegion()返回的值将不会反映绘图系统所使用的剪裁区域。
*/
class Q_GUI_EXPORT QPaintEvent : public QEvent
{
Q_EVENT_DISABLE_COPY(QPaintEvent);
protected:
QRect m_rect ;
QRegion m_region; //这个定义复杂
bool m_erased;
public:
//Constructs a paint event object with the region that needs to be updated.
//The region is specified by paintRegion.
explicit QPaintEvent(const QRegion & paintRegion);
explicit QPaintEvent(const QRect & paintRect );
//Constructs a paint event object with the rectangle that needs to be updated.
//The region is specified by paintRect.
~QPaintEvent();
QPaintEvent * clone() const override { return new QPaintEvent(* this); }
inline const QRect & rect () const { return m_rect ; }
inline const QRegion & region() const { return m_region; }
}; //完结 class QPaintEvent : public QEvent
++测试一下 :
(3)QResizeEvent 大小改变 :
/*
The QResizeEvent class contains event parameters for resize events.
调整大小事件被发送到已调整大小的控件。
事件处理程序QWidget::resizeEvent()接收调整大小事件。
*/
class Q_GUI_EXPORT QResizeEvent : public QEvent
{
Q_EVENT_DISABLE_COPY(QResizeEvent);
protected:
QSize m_size, m_oldSize; //class QSize { int wd; int ht; };
friend class QApplication;
public:
//Constructs a resize event with the new and old widget sizes,
// size and oldSize respectively.
QResizeEvent(const QSize & size, const QSize & oldSize);
~QResizeEvent();
QResizeEvent * clone() const override { return new QResizeEvent(*this); }
inline const QSize & size() const { return m_size ; }
inline const QSize & oldSize() const { return m_oldSize; }
}; //完结 class QResizeEvent : public QEvent
++测试 :
(4)QMoveEvent 控件移动 :
/*
The QMoveEvent class contains event parameters for move events.
移动事件被发送到相对于其父级已移动到新位置的控件。
事件处理程序QWidget::moveEvent()接收移动事件。
*/
class Q_GUI_EXPORT QMoveEvent : public QEvent //组件的被移动事件
{
Q_EVENT_DISABLE_COPY(QMoveEvent);
protected:
QPoint m_pos, m_oldPos;
friend class QApplication;
public:
//Constructs a move event with the new and old widget positions,
// pos and oldPos respectively.
QMoveEvent(const QPoint & pos, const QPoint & oldPos);
~QMoveEvent();
QMoveEvent * clone() const override { return new QMoveEvent(*this); }
//Returns the new position of the widget.
//This excludes the window frame for top level widgets.
inline const QPoint & pos() const { return m_pos ; } //位置信息不包含窗体的边框
inline const QPoint & oldPos() const { return m_oldPos; }
}; //完结 class QMoveEvent : public QEvent
++举例子 :
(5)
谢谢