Robin
Robin

Reputation: 129

Qt : catched mouseMoseEvent dont interact with QWebView html page element

I catch the mouseMoveEvent of my QWebView for restarting a timer of a screensaver. The problem is that now the mouseMoveEvent isnt distribued to the HTML elements so its impossible for example to move a sliding bar on the page.

I use connect to bind mouseMoveEvent to the restart slot :

QObject::connect(_view, SIGNAL(mouseMoveEvent(QMouseEvent*)), _mediaPlayer, SLOT(stop()));

WebView class :

class WebView : public QWebView
{
    Q_OBJECT
public:

    WebView(QString menu) : _menuDesc(menu) {};
    WebView(){};

    void            setMenuDesc(QString menu) {_menuDesc = menu;};
    QString         getMenuDesc() {return _menuDesc;};
    void            setCurrPage(QString page) {_currPage = page;};
    QString         getCurrPage() {return _currPage;};
    void            setCurrCategory(QString page) {_currPage = page;};
    QString         getCurrCategory() {return _currPage;};

    void            mouseMoveEvent(QMouseEvent *)
    {
        emit mouseMoved();
    };

signals :
    void mouseMoved();

private:

    QString             _menuDesc = 0;
    QString             _currPage;
    QString             _currCategory = 0;
};

Is there a solution to still catch the signal and pass it to the HTML page?

Upvotes: 2

Views: 322

Answers (2)

hiitiger
hiitiger

Reputation: 545

Seems you misunderstand event handler and signal usages.

mouseMoveEvent is a member method of QWidget, is not a signal so you cannot connect to it. You can override it in you subclass and emit your own signal.

And if a QWidget's mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. Maybe you need to call setMouseTracking too.

Upvotes: 2

Aaron
Aaron

Reputation: 1191

mouseMoveEvent is not a signal but an event handler. You can reimplement this event handler and let it emit a signal you can connect to if you need that.

Like this:

MyWebView::mouseMoveEvent(QMouseEvent * e) {
   emit mouseMoved(); // this would be signal you could connect to.
}

Upvotes: 2

Related Questions