我建议考虑使用 QToolButton.clicked 信号与 QMenu.popup 方法与 setMenu - 这可能会破坏模态。
我尝试为您设置一个示例 - 但它不会阻止 QMovie ......所以也许您可以使用此示例来测试视频播放器与 Qmovie 的不同选项,看看它是否仍然阻止您的事件循环:
from PyQt4 import QtGui, QtCore
MOVIE_FILE = '/path/to/ajax_loader.gif'
class MyDialog(QtGui.QDialog):
def __init__( self, parent = None ):
super(MyDialog, self).__init__(parent)
self._menu = QtGui.QMenu(self)
self._menu.addAction('Action A')
self._menu.addAction('Action B')
self._menuButton = QtGui.QToolButton(self)
self._modalButton = QtGui.QToolButton(self)
self._nonModalButton = QtGui.QToolButton(self)
self._feedbackLabel = QtGui.QLabel(self)
self._startTime = QtCore.QDateTime.currentDateTime()
self._menuButton.setPopupMode(self._menuButton.InstantPopup)
movie = QtGui.QMovie(self)
movie.setFileName(MOVIE_FILE)
movie.start()
self._feedbackLabel.setMovie(movie)
hlayout = QtGui.QHBoxLayout()
hlayout.addWidget(self._menuButton)
hlayout.addWidget(self._modalButton)
hlayout.addWidget(self._nonModalButton)
hlayout.addStretch()
vlayout = QtGui.QVBoxLayout()
vlayout.addLayout(hlayout)
vlayout.addWidget(self._feedbackLabel)
self.setLayout(vlayout)
self.adjustSize()
# setup different menu examples
self._menuButton.setMenu(self._menu)
self._modalButton.clicked.connect(self.showModalMenu)
self._nonModalButton.clicked.connect(self.showNonModalMenu)
self._menu.triggered.connect(self.showAction)
def showModalMenu( self ):
point = self._modalButton.rect().bottomLeft()
global_point = self._modalButton.mapToGlobal(point)
self._menu.exec_(global_point)
def showNonModalMenu( self ):
point = self._nonModalButton.rect().bottomLeft()
global_point = self._nonModalButton.mapToGlobal(point)
self._menu.popup(global_point)
def showAction( self, action ):
print action.text()
if ( __name__ == '__main__' ):
app = QtGui.QApplication([])
dlg = MyDialog()
dlg.show()
app.exec_()