Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Custom context menu in QtWebEngineView (in Python)
QtWS25 Last Chance

Custom context menu in QtWebEngineView (in Python)

Scheduled Pinned Locked Moved Solved QtWebEngine
3 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harborman
    wrote on last edited by
    #1

    How can I make a custom context menu that opens up when I right click on a webpage?
    Naturally I want to be able to use actions such as saving an image in my browser.
    I want to replace the default one that is apparently inherited from Chromium and add actions to it.

    I'm new with PyQt5 and didn't find any examples on Duckduckgo. Seems that most documentation and examples are for C++.

    JonBJ 1 Reply Last reply
    0
    • H Harborman

      How can I make a custom context menu that opens up when I right click on a webpage?
      Naturally I want to be able to use actions such as saving an image in my browser.
      I want to replace the default one that is apparently inherited from Chromium and add actions to it.

      I'm new with PyQt5 and didn't find any examples on Duckduckgo. Seems that most documentation and examples are for C++.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Harborman
      Have a go at https://stackoverflow.com/questions/66495337/how-to-customize-python-pyqt5-qwebengineview-context-menu.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Harborman
        wrote on last edited by
        #3

        @JonB said in Custom context menu in QtWebEngineView (in Python):

        @Harborman
        Have a go at https://stackoverflow.com/questions/66495337/how-to-customize-python-pyqt5-qwebengineview-context-menu.

        Thank you. I managed to make a custom context menu using the information in that link. I put the webengine in its own class, and then made a completely new context menu using Qmenu.
        Here's the working context menu test:

        class Browser(QWebEngineView):

        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
        
         def contextMenuEvent(self, event):
            self.menus = QMenu()
            self.menus.addAction('Save Image')
            self.menus.popup(event.globalPos())
        

        class MainWindow(QMainWindow):

         def __init__(self, *args, **kwargs):
            super(MainWindow, self).__init__(*args, **kwargs)
            self.browser = Browser()
            self.setCentralWidget(self.browser)
            self.show()
            self.browser.load(QUrl("http://duckduckgo.com"))
        

        app = QApplication(sys.argv)
        app.setApplicationName("Context Menu test")
        window = MainWindow()
        app.exec_()

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved