PyQt4: Move context menu to position

坚强是说给别人听的谎言 提交于 2019-12-08 08:43:13

问题


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)

回答1:


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.

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

Or you can calculate your desired position before calling exec_.



来源:https://stackoverflow.com/questions/12629634/pyqt4-move-context-menu-to-position

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