View Single Post
Old 07-08-2014, 10:42 AM   #12
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
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?

Last edited by jackie_w; 07-08-2014 at 10:45 AM.
jackie_w is offline   Reply With Quote