Project

General

Profile

Stop signal from being sent to server

Added by Ulf Johnsson over 2 years ago

Hi.

I've encountered something I do not know how to solve.

I have a WPaintedWidget that (sometimes) need to track MouseMove-events.

To do this i have someting like this:

class MyWidget : public Wt::WPaintedWidget
{
public:
    MyWidget() : Wt::WPaintedWidget() {}

    void setMouseTracking(bool on) {
        if(m_mouseMoveConnection.isConnected()) {
            m_mouseMoveConnection.disconnect();
            m_mouseMoveConnection = Wt::Signals::connection();
        }

        if(on)
            m_mouseMoveConnection = mouseMoved().connect(this, &MyWidget::onMouseMove);
    }

    void onMouseMove(const Wt::WMouseEvent &mev) {
        // Do stuff!
    }

private:
    Wt::Signals::connection m_mouseMoveConnection;
}

The solution works in the sense that when calling MyWidget.setMouseTracking(true) MyWidget::onMoveMove
gets called, and when calling MyWidget::setMouseTracking(false) it doesnt.
My issue is even though the signal has been disconnected the browser still sends the signal to the server.
If I never register the listener in the first place no signals are being sent in the first place,
which is what I want to have happen when I disconnect them.

Is this possible top achieve?

BR, Ulf Johnsson.


Replies (1)

RE: Stop signal from being sent to server - Added by Bruce Toll over 2 years ago

As a workaround, I believe you can use addArea() to add a WRectArea (e.g. my_area) with the same height/width as your MyWidget. You can then control whether the browser sends mouseMoved by using my_area->mouseMoved().preventPropagation() with an appropriate argument.

    (1-1/1)