在gtkmm中捕获鼠标运动 [英] catch mouse motion in gtkmm
问题描述
当我按住鼠标中键时,我试图捕捉鼠标的运动。目标是在stl查看器中实现旋转功能。
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.
我发现了事件掩码 BUTTON2_MOTION_MASK
。但是我很难弄清楚哪个信号能够捕获到它。
I found the event mask BUTTON2_MOTION_MASK
. But I have a hard time figuring out which signal catches it.
这是我用来创建和挂钩事件的两行内容。这两行都在GtkApplicationWindow构造函数中。
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.
我设法使glArea小部件对这种滚动方式做出了反应。
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));
我连接的功能:
bool mainWindow::zoom(GdkEventScroll *eventScroll)
{
cout<<"test"<<endl;
return true;
}
推荐答案
我知道了。您需要同时添加Gdk :: Button1_MOTION_MASK和Gdk :: BUTTON_PRESS_MASK。
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将需要按下2个按钮。出于某种原因,它只是鼠标左键(我想要中键)。
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).
这篇关于在gtkmm中捕获鼠标运动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!