Issue
With older syntax we had to use the QtCore.SIGNAL("customContextMenuRequested(QPoint)"
thingy.
Now with Qt5 around-the-corner the older QtCore.SIGNAL
syntax is not cool any longer as it becomes absolute.
How to modify the working PyQt4 code posted below to make it compatible with PyQt5 (only concerned about connecting the right-click menu)?
class TableView(QtGui.QTableView):
def __init__(self, parent):
QtGui.QTableView.__init__(self, parent)
self.rcMenu=QtGui.QMenu(self)
self.rcMenu.addAction('My Action')
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.connect(self, QtCore.SIGNAL("customContextMenuRequested(QPoint)" ), self.onRightClick)
def onRightClick(self, QPos=None):
parent=self.sender()
pPos=parent.mapToGlobal(QtCore.QPoint(5, 20))
mPos=pPos+QPos
self.rcMenu.move(mPos)
self.rcMenu.show()
Solution
Replace:
self.connect(self, QtCore.SIGNAL("customContextMenuRequested(QPoint)" ), self.onRightClick)
with:
self.customContextMenuRequested.connect(self.onRightClick)
class TableView(QtGui.QTableView):
def __init__(self, parent):
QtGui.QTableView.__init__(self, parent)
self.rcMenu=QtGui.QMenu(self)
self.rcMenu.addAction('My Action')
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.onRightClick)
def onRightClick(self, QPos=None):
parent=self.sender()
pPos=parent.mapToGlobal(QtCore.QPoint(5, 20))
mPos=pPos+QPos
self.rcMenu.move(mPos)
self.rcMenu.show()
Answered By - alphanumeric
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.