QGLWidget 上的上下文菜单问题
我对 QGLWidget 和 QTreeView 上的自定义上下文菜单有疑问。我将 QTreeview 和 QGLWidget 添加到带有拆分器的常见小部件中。我通过以下代码打开上下文菜单。
setContextMenuPolicy(Qt::CustomContextMenu);
QMenu::exec(actions, mapToGlobal(QPoint(x, y)),actions.at(0),this);
actions 是 QAction 的列表。
当鼠标按下 QGLWidget 时,如果满足某些条件,鼠标光标会发生变化。右键单击打开上下文菜单后,如果在其中一个菜单项上按下鼠标,则一切正常。如果没有在上下文菜单的一项上按下鼠标,则上下文菜单将关闭并出现问题。问题是,即使按下鼠标时所有条件都满足,鼠标光标也不会改变。我不确定 QWidget 是否在这里失去焦点。因此,我尝试在鼠标按下事件中设置焦点。但没有太大帮助。任何解决这个问题的建议。
谢谢你!
I have an issue with Custom Context menu on QGLWidget and QTreeView. I have QTreeview and QGLWidget added to a common widget with splitter. I open context menu by the following code.
setContextMenuPolicy(Qt::CustomContextMenu);
QMenu::exec(actions, mapToGlobal(QPoint(x, y)),actions.at(0),this);
actions is a list of QActions.
On mouse press on the QGLWidget, the mouse cursor changes if certain conditions are met. After opening the context menu on right click, if mouse press is done on the one of the menu items, everything is fine. If mouse press does not happen on one of the items of the context menu, the context menu closes and the problem starts. The problem is mouse cursor does not change even if all conditions are satisfied when a mouse press happens. I am not sure if the QWidget lost focus here. So, I have tried setting the focus in the mouse press event. But of not much help. Any suggestions to get over this issue.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想问题可能是事件没有传递到父小部件。
中添加以下语句即可
只需在 mouseReleaseEvent() QGLWidget::mouseReleaseEvent(event);
I guess the problem might be that the event is not passed on to the parent widget.
Just add the following statement in you mouseReleaseEvent()
QGLWidget::mouseReleaseEvent(event);