• qt 如何给图元安装一个场景事件过滤器?


    void QGraphicsItem::installSceneEventFilter(QGraphicsItem *filterItem)

    class LabCrossEvent : public QGraphicsObject
    {
        Q_OBJECT
    public:
        LabCrossEvent() {}
        virtual ~LabCrossEvent() {}
    
        virtual QRectF boundingRect() const
        {
            return QRectF();
        }
    
        virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR)
        {
    
        }
    signals:
        void hover();
    public slots:
    protected:
        bool LabCrossEvent::sceneEventFilter(QGraphicsItem * watched, QEvent * event)
        {
            qDebug() << "||" << event->type();
            if(event->type() == QEvent::GraphicsSceneMove)
            {
                emit hover(); // signal that the item was moved
            }
            //return  sceneEventFilter(watched,event);
            return false; // pass the event to the original target item
        }
    
    };
    
    
            QGraphicsItem* dL_Item = this->addRect(-22,-std::abs(high_dL),44,height_dL,QPen(QColor("#239B56")));
            
            //安装的过场景事件滤器必须添加到场景中,否则事件过滤器无效
            this->addItem(&_labCrossEvent);
            //为矩形图元安装一个场景事件过滤器
            dL_Item->installSceneEventFilter(&_labCrossEvent);
    
  • 相关阅读:
    9. MySQL
    python第四课
    python第三课pycharm的使用
    python第二课
    python第一课
    Python3基础-网络编程(8)
    Python3基础-异常处理(7)
    Python3基础-面向对象(6)
    Python3基础-模块和包(5)
    Python3基础-文件处理(4)
  • 原文地址:https://www.cnblogs.com/cheungxiongwei/p/9563864.html
Copyright © 2020-2023  润新知