PySide how to get QWebInspector in the same window

I just started living in the Qt realm (coming from PyGTK) and I use PySide. So I found this great example in another answer here in the table sharing section .

import sys from PySide.QtCore import * from PySide.QtGui import * from PySide.QtWebKit import * app = QApplication(sys.argv) web = QWebView() web.settings().setAttribute( QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) # or globally: # QWebSettings.globalSettings().setAttribute( # QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) web.load(QUrl("http://www.google.com")) web.show() inspect = QWebInspector() inspect.setPage(web.page()) inspect.show() sys.exit(app.exec_()) 

My question is this: how do I get the inspector to appear in the same window, and not in a new one? I understand that I need to add the QWebInspector to another widget inside the main window (for example, vbox), I want to know how to connect this event to the signal in the context menu of the "Inspect" trigger. In PyGTK I will need to use .connect (), but I cannot find the correct SIGNAL for this particular action.

Thank you for your time guys / gala

+4
source share
1 answer

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_()) 
+3
source

Source: https://habr.com/ru/post/1446355/


All Articles