zoukankan      html  css  js  c++  java
  • 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);
    
  • 相关阅读:
    DAO模式多表联查
    使用ADO.NET访问数据库
    连接查询和分组查询
    模糊查询和聚合函数
    poj 1220 NUMBER BASE CONVERSION
    poj 1964 City Game
    Odd number problem
    POJ 2983 M × N Puzzle
    L O V E
    【Mybatis】【3】处理大于号小于号及其他特殊字符
  • 原文地址:https://www.cnblogs.com/cheungxiongwei/p/9563864.html
Copyright © 2011-2022 走看看