[Solved] Python/Pyqt - QtCore.Qt.RightButton not responding
-
Hi,
I'm trying to create a right-click menu.
All QShortCuts with keyboard buttons work, but not mouse-click QShortcuts...Here is my code:
@shortcut = QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.RightButton), parent)
// popupMenu func code
widget.connect(shortcut, QtCore.SIGNAL("activated()"), popupMenu)@Is there anything I'm missing?
Thanks!!
-
Any ideas?
Thanks in advanced!!
-
Hi,
I'm not sure that you can use QShortcut in this way. However, QWidget has a built in approach to capturing right mouse clicks and rendering context menus as the following example shows:
@
from PyQt4.QtCore import *
from PyQt4.QtGui import *class Widget(QWidget):
def init(self, parent=None):
QWidget.init(self, parent)self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showMenu) def showMenu(self, pos): menu=QMenu(self) menu.addAction(QAction("Item 1", menu)) menu.addAction(QAction("Item 2", menu)) menu.addAction(QAction("Item 3", menu)) menu.popup(self.mapToGlobal(pos))
if name=="main":
from sys import argv, exit
a=QApplication(argv)
w=Widget()
w.show()
exit(a.exec_())
@Hope this helps ;o)
-
Thanks so much, jazzycamel! :)
That worked great!!!