【Qt】QML-03:QQuickView自定义鼠标事件

1、简述

QQuickView集成自QQuickWindow,QQuickWindow集成自QWindow,QWindow集成自QObject,因此通过的QObject的事件过滤,过滤出QWindow的鼠标事件,也可以自定义处理鼠标事件。

2、代码实现

class LaoerQuickView : public QQuickView {
public:
    LaoerQuickView() {
    	# a)注册事件过滤
        installEventFilter(this);
    }
protected:
	bool eventFilter(QObject *target, QEvent *event)
	{    
    	if (target == this ) 
    	{        
        	if (event->type() == QEvent::KeyPress) 
        	{            
        		QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);            
            	if (keyEvent->key() == Qt::Key_Space) 
            	{                
                	focusNextChild();                
                	return true;            
            	}        
        	}    
    	}    
    	return QQuickView::eventFilter(target, event);
	}
	
    void mousePressEvent(QMouseEvent* event)
    {
        // TODO event
        QQuickView::mousePressEvent(event);
    }

    void mouseMoveEvent(QMouseEvent* event)
    {
        // TODO event
        QQuickView::mouseMoveEvent(event);
    }

    void mouseReleaseEvent(QMouseEvent* event)
    {
        // TODO event
        QQuickView::mouseReleaseEvent(event);
    }
};

你可能感兴趣的:(QML,qt)