问题
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