No need to do anything special for the context menu. Just add an inspector widget to your layout and hide() it to start. The default context menu action can then show() inspector as needed.
A somewhat complicated problem is how to hide the inspector again as soon as it is shown, since there is no corresponding context menu item for this.
The demo script below simply creates a key combination to hide / show the inspector:
from PySide import QtGui, QtCore, QtWebKit class Window(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.view = QtWebKit.QWebView(self) self.view.settings().setAttribute( QtWebKit.QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) self.inspector = QtWebKit.QWebInspector(self) self.inspector.setPage(self.view.page()) self.inspector.hide() self.splitter = QtGui.QSplitter(self) self.splitter.addWidget(self.view) self.splitter.addWidget(self.inspector) layout = QtGui.QVBoxLayout(self) layout.addWidget(self.splitter) QtGui.QShortcut(QtGui.QKeySequence('F7'), self, self.handleShowInspector) def handleShowInspector(self): self.inspector.setShown(self.inspector.isHidden()) if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) window = Window() window.view.load(QtCore.QUrl('http://www.google.com')) window.show() sys.exit(app.exec_())
source share