My next question ... I need to create a right-click context menu on a single QTextBrowser widget, which is part of a busy QDialog.
This simplified code worked OK in PyQt4 but not PyQt5. I think the problem is in the
red bits.
Code:
from PyQt4.Qt import SIGNAL
class MyDlg(QDialog):
def __init__(self, epub, parent=None):
QDialog.__init__(self)
... ...
self.browser = QTextBrowser()
self.browser.setContextMenuPolicy(Qt.CustomContextMenu)
self.browser.customContextMenuRequested.connect(self.showSnippetMenu)
self.create_context_menu()
def showSnippetMenu(self, pos):
self.snipmenu.popup(self.browser.mapToGlobal(pos))
def create_context_menu(self):
self.snipmenu = QMenu(self.browser)
self.myAction1 = self.createAction('Menu item label', self.myMethod1)
self.addActions(self.snipmenu, (self.myAction1, ...))
def createAction(self, text, slot=None):
action = QAction(text, self)
if slot is not None:
self.connect(action, SIGNAL("triggered()"), slot)
return action
def myMethod1(self):
... blah blah ...
Can anyone help? Maybe I need to switch over to using pre-written calibre special menu-creating functions. If so can you point me at the beginners' end of the knotty string , please?