I would like to set two things for submenus in PyQt:
- not open submenus when hovered
- no delay when submenus get opened by a click
I suppose that I had to modify the hover behavior of the QAction
object that is returned by the menuAction()
method of the submenu object - but how to do this?
There is a QStyle::SH_Menu_SubMenuPopupDelay
setting mentioned in the docs that is maybe what I need for the second but I also have no clue how to set this in PyQt.
My basic menu example:
#!/usr/bin/env python
from PyQt4 import QtGui
from PyQt4 import QtCore
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.menubar = QtGui.QMenuBar(self)
self.setMenuBar(self.menubar)
self.menuFile = QtGui.QMenu(self.menubar, title='File')
self.menubar.addAction(self.menuFile.menuAction())
self.submenu = QtGui.QMenu(self.menuFile, title='Submenu')
self.menuFile.addAction(QtGui.QAction(self, text="First"))
self.menuFile.addAction(self.submenu.menuAction())
self.menuFile.addAction(QtGui.QAction(self, text="Third"))
self.submenu.addAction(QtGui.QAction(self, text="First"))
self.submenu.addAction(QtGui.QAction(self, text="Second"))
self.submenu.addAction(QtGui.QAction(self, text="Third"))
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())