打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
QT 事件触发总结
  1. 不需要使用者绑定 只需要重写QT定义事件方法
    QT 事件触发总结 - 信号
  2. 需要使用者绑定 按照调用的优先级(由小到大)
    connect
    特点:最常用,(可以建立连接,也可根据需要取消连接)
connect(sender, SIGNAL(signal), receiver, SLOT(slot));      // 建立连接disconnect(sender, , receiver, SLOT(slot));                 // 取消连接

eventfiler
特点: 方便在多个sender间切换,有继承关系的能有效减少代码量

sender->installEventFilter(receiver);           // 注册筛选器sender->removeEventFilter(receiver);            // 移除筛选器bool eventFilter(QObject *obj, QEvent *event)   // 实现事件筛选器{    if (event->type() == QEvent::GraphicsSceneMousePress)   // 是否是鼠标按压操作    {        QGraphicsSceneMouseEvent *_pMoveEvent = static_cast<QGraphicsSceneMouseEvent*>(event);  // 强转为鼠标事件        if (_pMoveEvent->button() != Qt::RightButton)       // 不是右键操作        {            return QWidget::eventFilter(obj, event);        }        if (hitTest(_pMoveEvent->scenePos().toPoint()))     // 选中元素        {            if (m_eDrawType < 6 || m_eDrawType == 7 || m_eDrawType == 10 || m_eDrawType == 11)  // 允许显示右键的图元            {                if (m_eScoreMode < 3 || m_eScoreMode == 4)                                      // 允许显示右键的模式                {                    // 显示右键菜单                    QMenu *_pPopMenu = new QMenu();                    QAction *_pCreateAct = _pPopMenu->addAction("新建");                    connect(_pCreateAct, SIGNAL(triggered(bool)), this, SLOT(slotCreateQml()));                    _pPopMenu->addSeparator();                    QAction *_pEditAct = _pPopMenu->addAction("编辑");                    connect(_pEditAct, SIGNAL(triggered(bool)), this, SLOT(slotEditSubQml()));                    _pPopMenu->addSeparator();                    _pEditAct->setEnabled(false);                    // 其它操作                    _pPopMenu->exec(_pMoveEvent->screenPos());                    return true;                }            }        }    }    return QWidget::eventFilter(obj, event);}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
PyQt4 教程(5)
【第五节】PyQt5事件和信号
[PyQt Tutorial]5.Signals & Slots(信号与槽)
QT的重要的概念
Qt MetaObject System详解之五
Qt那点事儿(一)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服