<tfoot id='Qyib9'></tfoot>

<small id='Qyib9'></small><noframes id='Qyib9'>

<i id='Qyib9'><tr id='Qyib9'><dt id='Qyib9'><q id='Qyib9'><span id='Qyib9'><b id='Qyib9'><form id='Qyib9'><ins id='Qyib9'></ins><ul id='Qyib9'></ul><sub id='Qyib9'></sub></form><legend id='Qyib9'></legend><bdo id='Qyib9'><pre id='Qyib9'><center id='Qyib9'></center></pre></bdo></b><th id='Qyib9'></th></span></q></dt></tr></i><div id='Qyib9'><tfoot id='Qyib9'></tfoot><dl id='Qyib9'><fieldset id='Qyib9'></fieldset></dl></div>

      1. <legend id='Qyib9'><style id='Qyib9'><dir id='Qyib9'><q id='Qyib9'></q></dir></style></legend>
        • <bdo id='Qyib9'></bdo><ul id='Qyib9'></ul>
      2. 如何使用 target=“_blank"打开超链接在 PyQtWeb

        时间:2023-08-05

        <small id='2pCvA'></small><noframes id='2pCvA'>

            • <i id='2pCvA'><tr id='2pCvA'><dt id='2pCvA'><q id='2pCvA'><span id='2pCvA'><b id='2pCvA'><form id='2pCvA'><ins id='2pCvA'></ins><ul id='2pCvA'></ul><sub id='2pCvA'></sub></form><legend id='2pCvA'></legend><bdo id='2pCvA'><pre id='2pCvA'><center id='2pCvA'></center></pre></bdo></b><th id='2pCvA'></th></span></q></dt></tr></i><div id='2pCvA'><tfoot id='2pCvA'></tfoot><dl id='2pCvA'><fieldset id='2pCvA'></fieldset></dl></div>
                <tbody id='2pCvA'></tbody>

              <tfoot id='2pCvA'></tfoot>
                <legend id='2pCvA'><style id='2pCvA'><dir id='2pCvA'><q id='2pCvA'></q></dir></style></legend>
                  <bdo id='2pCvA'></bdo><ul id='2pCvA'></ul>

                  本文介绍了如何使用 target=“_blank"打开超链接在 PyQtWebEngine 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我使用 pyqt5 和 PyQtWebEngine 制作了一个 Web 浏览器.它工作正常,但是当我单击带有 target=_blank"的超链接时那么它不起作用,但我将如何解决它.您可以通过点击此链接查看其源代码 https://github.com/SaptakBhoumik/WebPlus.请检查我的代码并告诉我该怎么做

                  I have made a web browser using pyqt5 and PyQtWebEngine.It works fine but when I click on a hyperlink with target="_blank" then it does not work but how will I fix it. You can view its source code by clicking on this link https://github.com/SaptakBhoumik/WebPlus . Please review my code and tell me what to do

                  推荐答案

                  如 文档:

                  _blank:通常是一个新标签页,但用户可以配置浏览器打开一个新窗口.

                  _blank: usually a new tab, but users can configure browsers to open a new window instead.

                  也就是说,目标不是重新加载页面,而是创建一个新选项卡,然后为了获得该请求,您必须重写 QWebEngineView(或 QWebEnginePage)的 createWindow 方法:

                  That is, the objective is not to reload the page but to create a new tab, and then to obtain that request you must override the createWindow method of QWebEngineView (or QWebEnginePage):

                  from functools import cached_property
                  import sys
                  
                  
                  from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets
                  
                  
                  class WebView(QtWebEngineWidgets.QWebEngineView):
                      def createWindow(self, type_):
                          if not isinstance(self.window(), Browser):
                              return
                  
                          if type_ == QtWebEngineWidgets.QWebEnginePage.WebBrowserTab:
                              return self.window().tab_widget.create_tab()
                  
                  
                  class TabWidget(QtWidgets.QTabWidget):
                      def create_tab(self):
                          view = WebView()
                  
                          index = self.addTab(view, "(Untitled)")
                          self.setTabIcon(index, view.icon())
                          view.titleChanged.connect(
                              lambda title, view=view: self.update_title(view, title)
                          )
                          view.iconChanged.connect(lambda icon, view=view: self.update_icon(view, icon))
                          self.setCurrentWidget(view)
                          return view
                  
                      def update_title(self, view, title):
                          index = self.indexOf(view)
                          self.setTabText(index, title)
                  
                      def update_icon(self, view, icon):
                          index = self.indexOf(view)
                          self.setTabIcon(index, icon)
                  
                  
                  class Browser(QtWidgets.QMainWindow):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                          self.setCentralWidget(self.tab_widget)
                  
                          view = self.tab_widget.create_tab()
                          view.load(
                              QtCore.QUrl(
                                  "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_a_target"
                              )
                          )
                  
                      @cached_property
                      def tab_widget(self):
                          return TabWidget()
                  
                  
                  def main():
                      app = QtWidgets.QApplication(sys.argv)
                      w = Browser()
                      w.show()
                      sys.exit(app.exec_())
                  
                  
                  if __name__ == "__main__":
                      main()
                  

                  注意:建议您查看官方示例:WebEngine Widgets 简单浏览器示例,以及在 PySide2 很容易翻译成 PyQt5 实现了这个功能和更多功能.

                  Note: I recommend that you review the official example: WebEngine Widgets Simple Browser Example, in addition to its implementation in PySide2 which is easily translatable to PyQt5 where this feature and many more are implemented.

                  这篇关于如何使用 target=“_blank"打开超链接在 PyQtWebEngine 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将旧信号和插槽转换为新样式的正确方法? 下一篇:授予对 Cam &amp; 的访问权限将 Python 用于 PyQt

                  相关文章

                  最新文章

                      <i id='YLUc0'><tr id='YLUc0'><dt id='YLUc0'><q id='YLUc0'><span id='YLUc0'><b id='YLUc0'><form id='YLUc0'><ins id='YLUc0'></ins><ul id='YLUc0'></ul><sub id='YLUc0'></sub></form><legend id='YLUc0'></legend><bdo id='YLUc0'><pre id='YLUc0'><center id='YLUc0'></center></pre></bdo></b><th id='YLUc0'></th></span></q></dt></tr></i><div id='YLUc0'><tfoot id='YLUc0'></tfoot><dl id='YLUc0'><fieldset id='YLUc0'></fieldset></dl></div>

                        <bdo id='YLUc0'></bdo><ul id='YLUc0'></ul>

                    1. <tfoot id='YLUc0'></tfoot>

                      <small id='YLUc0'></small><noframes id='YLUc0'>

                      <legend id='YLUc0'><style id='YLUc0'><dir id='YLUc0'><q id='YLUc0'></q></dir></style></legend>