QT6 源,六章,事件系统(3)QEvent 的直接子类:QPaintEvent 重绘、QResizeEvent 大小改变,QMoveEvent 窗体移动,

(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)

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangzhangkeji

谢谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值