catch mouse motion in gtkmm

怎甘沉沦 提交于 2019-12-12 03:54:41

问题


I am trying to catch the mouse motion when I hold the mouse middle button. The goal is to implement a rotation feature in an stl viewer.

I found the event mask BUTTON2_MOTION_MASK. But I have a hard time figuring out which signal catches it.

Here's the two line I use to create and hook the event. These two line are inside a GtkApplicationWindow Constructor.

glWidget.add_events(Gdk::BUTTON2_MOTION_MASK);
glWidget.signal_motion_notify_event().connect(sigc::mem_fun(*this,&mainWindow::rotate));

Here's the function I am trying to connect.

bool mainWindow::rotate(GdkEventMotion* motion_event)
{
    cout<<"test"<<endl;
}

Am I using the correct method? The code does not react when I hold the middle mouse button and move mouse.

I managed to get glArea widget to react to scrolling this way.

glWidget.add_events(Gdk::SMOOTH_SCROLL_MASK);

glWidget.signal_scroll_event().connect(sigc::mem_fun(*this,&mainWindow::zoom));

the function I connected:

bool mainWindow::zoom(GdkEventScroll *eventScroll)
{
        cout<<"test"<<endl;
        return true;
}

回答1:


I figured it out. You need to both add the Gdk::Button1_MOTION_MASK and the Gdk::BUTTON_PRESS_MASK.

glWidget.add_events(Gdk::Button1_MOTION_MASK | Gdk::BUTTON_PRESS_MASK);

This will catch the signal when the left mouse button is clicked and positioned on the widget.

BUTTON2_MOTION_MASK will require that 2 button are pressed. For some reason, it's only the left mouse button(I want the middle button).



来源:https://stackoverflow.com/questions/44595045/catch-mouse-motion-in-gtkmm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!