Custom context menu in QtWebEngineView (in Python)
-
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++.
-
-
@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_()