在gtk中绘制点/线。 C++
嘿,我正在使用 C++ 编写一个具有绘图区域的程序。我需要能够检测来自绘图区域的鼠标信号并在这些位置绘制点。我该怎么做?没有多少论坛可以帮助解决这些问题,而且文档也不清楚。有人可以帮我吗?
Hey I am using c++ to write a program which has a drawing area. I need to make it possible to detect mouse signals from the drawing area and draw points at these positions. How can I do this? There are not many forums which help with this stuff and the documentation is not clear. Can somebody please help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
gtk3 应用程序中的绘图是响应“绘图”信号而完成的。您将回调函数连接到“draw”信号,当 gtk+ 需要重绘窗口时,您的回调函数就会被调用。
回调看起来像这样:
现在,要处理鼠标单击,您需要将另一个回调函数连接到“button-press-event”:
请参阅 绘图区域参考文档 的一个小示例和 绘图区域演示以获得完整的应用程序。
Drawing in a gtk3 application is done in response to the "draw" signal. You connect a callback function to the "draw" signal, and when gtk+ needs to redraw the window, your callback is invoked.
The callback looks something like this:
Now, to handle mouse clicks, you'll need to connect another callback function to "button-press-event":
See the drawing area reference docs for a small example and the drawing area demo for a complete application.
将 gtkmm 与 C++ 一起使用,这是最好的选择。大多数事件可以通过重载特定的虚拟方法来捕获。对于鼠标按下,您可以重载
on_button_press_event
方法。 gtkmm.org 上的教程还不错(对于开源教程来说),您可以通过阅读基础知识并根据需要查看其他感兴趣的章节来获得良好的开端。Use gtkmm with C++, it's the best option. Most events can be captured by overloading a particular virtual method. For a mouse press, you overload the
on_button_press_event
method. The tutorial at gtkmm.org is not too bad (for open source tutorials that is), you can get a good start by reading about the basics and look at other chapters of interest as needed.