PyQt4:将上下文菜单移至 [英] PyQt4: Move context menu to position

查看:96
本文介绍了PyQt4:将上下文菜单移至的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何更改pyqt4中弹出菜单的位置?这段代码似乎没有做到.

How would you change the position of a popup menu in pyqt4? This code doesn't seem to do it.

    self.popMenu.exec_(self.table.mapToGlobal(point))
    position = self.popMenu.pos()
    self.popMenu.move(position.x() + 100, position.y() + 100)

推荐答案

您的版本不起作用,因为exec_同步打开菜单 ,即exec_将阻止/等待菜单被执行关闭.因此,move会在菜单关闭后进行处理.

You version doesn't work because exec_ opens the menu synchronously, i.e. exec_ will block/wait until menu is closed. So your move is processed after the menu is closed.

您可以使用popup代替exec_.那是异步的,因此在打开菜单时将执行以下代码.

You can use popup instead of exec_. That is asynchronous, so the following code will be executed while the menu is open.

或者您可以在调用exec_之前 计算所需的位置.

Or you can calculate your desired position before calling exec_.

这篇关于PyQt4:将上下文菜单移至的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆