wxEVT_LEFT_UP mouseEvent not triggering in the webview sample

31 views
Skip to first unread message

Raphael Stonehorse

unread,
Jan 31, 2024, 5:04:21 AMJan 31
to wx-u...@googlegroups.com
Hi!

I've added in the WebFrame::WebFrame constructor in the webview sample:


the following event binding:

    panel->Bind(wxEVT_LEFT_UP, [&](wxMouseEvent& event) {
        wxMessageBox(wxString::Format("The frame is clicked at {x=%d, y=%d}", event.GetPosition().x, event.GetPosition().y), "FrameClick", wxID_ANY) ;
        std::cout << event.GetPosition().x << " , " << event.GetPosition().y << std::endl;
        mouse_position = event.GetPosition();
    });

But I do not get any output

What am I doing wrong? How to make it work?


Vadim Zeitlin

unread,
Feb 15, 2024, 7:07:30 PMFeb 15
to wx-u...@googlegroups.com
On Wed, 31 Jan 2024 11:04:07 +0100 Raphael Stonehorse wrote:

RS> Hi!
RS>
RS> I've added in the WebFrame::WebFrame constructor in the webview sample:
RS>
RS> https://github.com/wxWidgets/wxWidgets/blob/WX_3_0_BRANCH/samples/webview/webview.cpp
RS>
RS> the following event binding:
RS>
RS> panel->Bind(wxEVT_LEFT_UP, [&](wxMouseEvent& event) {
RS> wxMessageBox(wxString::Format("The frame is clicked at {x=%d,
RS> y=%d}", event.GetPosition().x, event.GetPosition().y), "FrameClick",
RS> wxID_ANY) ;
RS> std::cout << event.GetPosition().x << " , " <<
RS> event.GetPosition().y << std::endl;
RS> mouse_position = event.GetPosition();
RS> });
RS>
RS> But I do not get any output
RS>
RS> What am I doing wrong? How to make it work?

One thing you're definitely doing wrong is that you're binding to the
mouse event on the panel but the panel is never going to get it, being
entirely covered by wxWebView as it probably is. You should bind to the web
view itself.

But generally speaking, I'd probably recommend handling mouse events in
wxWebView using JS and not wx itself as this should be more generally more
robust.

Good luck,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
https://www.tt-solutions.com/
Reply all
Reply to author
Forward
0 new messages