2

I want to disable the right click menu which appears by default when you create a QWebEngineView.

import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl

app = QApplication(sys.argv)

webBrowser = QWebEngineView()

#Some line here to delete the contextMenu

webBrowser.load(QUrl("https://stackoverflow.com/"))
webBrowser.show()

sys.exit(app.exec_())

In the doc we can find a class QWebEngineContextMenuData which "provides context data for populating or extending a context menu with actions..." but nothing to delete in here?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
PaulCrp
  • 624
  • 1
  • 8
  • 19

2 Answers2

5

To disable the default widgets menu then the contextMenuPolicy must be set to Qt::NoContextMenu:

webBrowser.setContextMenuPolicy(Qt.NoContextMenu)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Perfect, just what i'm looking for. Thanks' a lot! But in this example to be totally transparent for who read this you need to call Qt.NoContextMenu trough QtCore because i'm not import Qt. I'm disable it by doing webBrowser.setContextMenuPolicy(QtCore.Qt.NoContextMenu) – PaulCrp Oct 03 '20 at 14:00
1

In PyQt6 it is:

webbrowser.setContextMenuPolicy(PyQt6.QtCore.Qt.ContextMenuPolicy.NoContextMenu)
IkonoDim
  • 21
  • 4