久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    1. <i id='MWpaK'><tr id='MWpaK'><dt id='MWpaK'><q id='MWpaK'><span id='MWpaK'><b id='MWpaK'><form id='MWpaK'><ins id='MWpaK'></ins><ul id='MWpaK'></ul><sub id='MWpaK'></sub></form><legend id='MWpaK'></legend><bdo id='MWpaK'><pre id='MWpaK'><center id='MWpaK'></center></pre></bdo></b><th id='MWpaK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='MWpaK'><tfoot id='MWpaK'></tfoot><dl id='MWpaK'><fieldset id='MWpaK'></fieldset></dl></div>
      <tfoot id='MWpaK'></tfoot>
          <bdo id='MWpaK'></bdo><ul id='MWpaK'></ul>
      1. <legend id='MWpaK'><style id='MWpaK'><dir id='MWpaK'><q id='MWpaK'></q></dir></style></legend>

        如何使用 QWebEngineView 打開下載文件對話框?

        How to open download file dialog with QWebEngineView?(如何使用 QWebEngineView 打開下載文件對話框?)

          1. <legend id='zAQ8P'><style id='zAQ8P'><dir id='zAQ8P'><q id='zAQ8P'></q></dir></style></legend>
              <tfoot id='zAQ8P'></tfoot>
              <i id='zAQ8P'><tr id='zAQ8P'><dt id='zAQ8P'><q id='zAQ8P'><span id='zAQ8P'><b id='zAQ8P'><form id='zAQ8P'><ins id='zAQ8P'></ins><ul id='zAQ8P'></ul><sub id='zAQ8P'></sub></form><legend id='zAQ8P'></legend><bdo id='zAQ8P'><pre id='zAQ8P'><center id='zAQ8P'></center></pre></bdo></b><th id='zAQ8P'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zAQ8P'><tfoot id='zAQ8P'></tfoot><dl id='zAQ8P'><fieldset id='zAQ8P'></fieldset></dl></div>

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

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

                    <tbody id='zAQ8P'></tbody>
                  本文介紹了如何使用 QWebEngineView 打開下載文件對話框?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在構建一個 pyqt5 桌面界面,我在其中使用 QWebEngineView 來顯示一個 html 文件,我在其中顯示一個傳單地圖.這工作正常.下一步是導出用戶添加到地圖的所有要素.當我點擊地圖上的導出功能"時,什么也沒有發(fā)生,但是當我在 Chromium 網(wǎng)絡瀏覽器上打開相同的 html 文件時,導出功能"會打開下載對話框.

                  I'm building a pyqt5 desktop interface where I'm using QWebEngineView to show a html file where I show a Leaflet map. This is working fine. The next step is to export all features the user added to the map. When I click on "Export Features" on the map nothing happen, but when I open the same html file on my Chromium web browser, the "Export feature" opens the download dialog fine.

                  PyQt5 腳本:

                  self.MainWindow.webMapViewer = QtWebEngineWidgets.QWebEngineView()
                  self.MainWindow.webPageLayout.addWidget(self.MainWindow.webMapViewer)
                  self.html_path = os.path.split(os.path.abspath(__file__))[0] + r'/html/test.html'
                  self.MainWindow.webMapViewer.load(QtCore.QUrl().fromLocalFile(self.html_path))
                  

                  HTML:

                  <!DOCTYPE html>
                          <html lang="en">
                            <head>
                              <meta charset="utf-8">
                              <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
                              <title>FazMaraneyRGB_transparent_mosaic_group1</title>
                  
                              <!-- Leaflet -->
                              <link rel="stylesheet"  />
                              <script src="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.js"></script>
                  
                              <!-- Leaflet.draw -->
                              <link rel="stylesheet"  />
                              <script src="https://unpkg.com/leaflet-draw@0.4.1/dist/leaflet.draw.js"></script>
                  
                              <!-- Leaflet Ajax -->
                              <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-ajax/2.1.0/leaflet.ajax.min.js"></script>
                  
                              <!-- Leaflet Measument -->
                              <link rel="stylesheet"  />
                              <script src="http://ljagis.github.io/leaflet-measure/leaflet-measure.min.js"></script>
                  
                  
                              <style>
                                  body { margin:0; padding:0; }
                                  body, table, tr, td, th, div, h1, h2, input { font-family: "Calibri", "Trebuchet MS", "Ubuntu", Serif; font-size: 11pt; }
                                  #map { position:absolute; top:0; bottom:0; width:100%; } /* full size */
                                  .ctl {
                                      padding: 2px 10px 2px 10px;
                                      background: white;
                                      background: rgba(255,255,255,0.9);
                                      box-shadow: 0 0 15px rgba(0,0,0,0.2);
                                      border-radius: 5px;
                                      text-align: right;
                                  }
                                  .title {
                                      font-size: 18pt;
                                      font-weight: bold;
                                  }
                                  .src {
                                      font-size: 10pt;
                                  }
                                  #delete, #export {
                                      position: absolute;
                                      top:100px;
                                      right:10px;
                                      z-index:100;
                                      background:white;
                                      color:black;
                                      padding:6px;
                                      border-radius:4px;
                                      font-family: 'Helvetica Neue';
                                      cursor: pointer;
                                      font-size:12px;
                                      text-decoration:none;
                                  }
                                  #export {
                                      top:130px;
                                  }
                              </style>
                  
                          </head>
                          <body>
                  
                          <div id='map'></div>
                          <div id='delete'>Delete Features</div>
                          <a href='#' id='export'>Export Features</a>
                  
                          <script>
                          /* **** Leaflet **** */
                  
                          // Base layers
                          //  .. OpenStreetMap
                          var osm = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {attribution: '&copy; <a >OpenStreetMap</a> contributors'});
                  
                          //  .. White background
                          var white = L.tileLayer("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAAA1BMVEX///+nxBvIAAAAH0lEQVQYGe3BAQ0AAADCIPunfg43YAAAAAAAAAAA5wIhAAAB9aK9BAAAAABJRU5ErkJggg==");
                  
                          // Overlay layers (TMS)
                          var lyr1 = L.tileLayer('./tiles/{z}/{x}/{y}.png', {tms: true, maxZoom: 22, opacity: 0.9, attribution: ""});
                  
                          // Map
                          var map = L.map('map', {
                              measureControl: true,
                              center: [-18.3604868606589, -52.694255477616245],
                              zoom: 22,
                              minZoom: 0,
                              maxZoom: 22,
                              layers: [osm]
                          });
                  
                          lyr1.addTo(map);
                  
                          //Geojson Layers
                  
                  
                          var basemaps = {"OpenStreetMap": osm, "Without background": white}
                          var overlaymaps = {"Layer 1": lyr1}
                  
                          // Title
                          var title = L.control();
                          title.onAdd = function(map) {
                              this._div = L.DomUtil.create('div', 'ctl title');
                              this.update();
                              return this._div;
                          };
                          title.update = function(props) {
                              this._div.innerHTML = "FazMaraneyRGB_transparent_mosaic_group1";
                          };
                          title.addTo(map);
                  
                          // Note
                          var src = 'Generated by Hawkit';
                          var title = L.control({position: 'bottomleft'});
                          title.onAdd = function(map) {
                              this._div = L.DomUtil.create('div', 'ctl src');
                              this.update();
                              return this._div;
                          };
                          title.update = function(props) {
                              this._div.innerHTML = src;
                          };
                          title.addTo(map);
                  
                          var featureGroup = L.featureGroup().addTo(map);
                  
                          var drawControl = new L.Control.Draw({
                              edit: {
                                  featureGroup: featureGroup
                              }
                          }).addTo(map);
                  
                          map.on('draw:created', function(e) {
                  
                              // Each time a feaute is created, it's added to the over arching feature group
                              featureGroup.addLayer(e.layer);
                          });
                  
                          // on click, clear all layers
                          document.getElementById('delete').onclick = function(e) {
                              featureGroup.clearLayers();
                          }
                  
                          document.getElementById('export').onclick = function(e) {
                              // Extract GeoJson from featureGroup
                              var data = featureGroup.toGeoJSON();
                  
                              // Stringify the GeoJson
                              var convertedData = 'text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(data));
                  
                              // Create export
                              document.getElementById('export').setAttribute('href', 'data:' + convertedData);
                              document.getElementById('export').setAttribute('download','data.geojson');
                          }
                  
                  
                          // Add base layers
                          L.control.layers(basemaps, overlaymaps, {collapsed: true}).addTo(map);
                  
                          // Fit to overlay bounds (SW and NE points with (lat, lon))
                          map.fitBounds([[-18.36827062251916, -52.6871074784942], [-18.35270287637126, -52.7014028427423]]);
                  
                          </script>
                  
                          </body>
                          </html>
                  

                  推薦答案

                  那個彈窗是由瀏覽器生成的,對于QWebEngine我們必須創(chuàng)建它.首先,必須檢測指示下載的信號,該信號是來自QWebEngineProfiledownloadRequested.該信號向我們發(fā)送一個處理下載的 QWebEngineDownloadItem 對象,在其中我們借助 QFileDialog 創(chuàng)建一個對話窗口.對于這種情況,我們將創(chuàng)建一個自定義的 QWebEnginePage,如下所示:

                  That popup window is generated by the browser, in the case of QWebEngine we must create it. To start, the signal indicating the download must be detected, and this signal is downloadRequested from the QWebEngineProfile. That signal sends us a QWebEngineDownloadItem object that handles the download, in it we create a dialog window with the help of QFileDialog. For this case we will create a custom QWebEnginePage as shown below:

                  index.html

                  <!DOCTYPE html>
                  <html lang="en">
                  
                  <head>
                      <meta charset="utf-8">
                      <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
                      <title>FazMaraneyRGB_transparent_mosaic_group1</title>
                  
                      <!-- Leaflet -->
                      <link rel="stylesheet"  />
                      <script src="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.js"></script>
                  
                      <!-- Leaflet.draw -->
                      <link rel="stylesheet"  />
                      <script src="https://unpkg.com/leaflet-draw@0.4.1/dist/leaflet.draw.js"></script>
                  
                      <!-- Leaflet Ajax -->
                      <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-ajax/2.1.0/leaflet.ajax.min.js"></script>
                  
                      <!-- Leaflet Measument -->
                      <link rel="stylesheet"  />
                      <script src="http://ljagis.github.io/leaflet-measure/leaflet-measure.min.js"></script>
                  
                      <style>
                          body {
                              margin: 0;
                              padding: 0;
                          }
                          
                          body,
                          table,
                          tr,
                          td,
                          th,
                          div,
                          h1,
                          h2,
                          input {
                              font-family: "Calibri", "Trebuchet MS", "Ubuntu", Serif;
                              font-size: 11pt;
                          }
                          
                          #map {
                              position: absolute;
                              top: 0;
                              bottom: 0;
                              width: 100%;
                          }
                          /* full size */
                          
                          .ctl {
                              padding: 2px 10px 2px 10px;
                              background: white;
                              background: rgba(255, 255, 255, 0.9);
                              box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
                              border-radius: 5px;
                              text-align: right;
                          }
                          
                          .title {
                              font-size: 18pt;
                              font-weight: bold;
                          }
                          
                          .src {
                              font-size: 10pt;
                          }
                          
                          #delete,
                          #export {
                              position: absolute;
                              top: 100px;
                              right: 10px;
                              z-index: 100;
                              background: white;
                              color: black;
                              padding: 6px;
                              border-radius: 4px;
                              font-family: 'Helvetica Neue';
                              cursor: pointer;
                              font-size: 12px;
                              text-decoration: none;
                          }
                          
                          #export {
                              top: 130px;
                          }
                      </style>
                  
                  </head>
                  
                  <body>
                  
                      <div id='map'></div>
                      <div id='delete'>Delete Features</div>
                      <a href='#' id='export'>Export Features</a>
                  
                      <script>
                          /* **** Leaflet **** */
                  
                          // Base layers
                          //  .. OpenStreetMap
                          var osm = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
                              attribution: '&copy; <a >OpenStreetMap</a> contributors'
                          });
                  
                          //  .. White background
                          var white = L.tileLayer("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAAA1BMVEX///+nxBvIAAAAH0lEQVQYGe3BAQ0AAADCIPunfg43YAAAAAAAAAAA5wIhAAAB9aK9BAAAAABJRU5ErkJggg==");
                  
                          // Overlay layers (TMS)
                          var lyr1 = L.tileLayer('./tiles/{z}/{x}/{y}.png', {
                              tms: true,
                              maxZoom: 22,
                              opacity: 0.9,
                              attribution: ""
                          });
                  
                          // Map
                          var map = L.map('map', {
                              measureControl: true,
                              center: [-18.3604868606589, -52.694255477616245],
                              zoom: 22,
                              minZoom: 0,
                              maxZoom: 22,
                              layers: [osm]
                          });
                  
                          lyr1.addTo(map);
                  
                          //Geojson Layers
                  
                          var basemaps = {
                              "OpenStreetMap": osm,
                              "Without background": white
                          }
                          var overlaymaps = {
                              "Layer 1": lyr1
                          }
                  
                          // Title
                          var title = L.control();
                          title.onAdd = function(map) {
                              this._div = L.DomUtil.create('div', 'ctl title');
                              this.update();
                              return this._div;
                          };
                          title.update = function(props) {
                              this._div.innerHTML = "FazMaraneyRGB_transparent_mosaic_group1";
                          };
                          title.addTo(map);
                  
                          // Note
                          var src = 'Generated by Hawkit';
                          var title = L.control({
                              position: 'bottomleft'
                          });
                          title.onAdd = function(map) {
                              this._div = L.DomUtil.create('div', 'ctl src');
                              this.update();
                              return this._div;
                          };
                          title.update = function(props) {
                              this._div.innerHTML = src;
                          };
                          title.addTo(map);
                  
                          var featureGroup = L.featureGroup().addTo(map);
                  
                          var drawControl = new L.Control.Draw({
                              edit: {
                                  featureGroup: featureGroup
                              }
                          }).addTo(map);
                  
                          map.on('draw:created', function(e) {
                  
                              // Each time a feaute is created, it's added to the over arching feature group
                              featureGroup.addLayer(e.layer);
                          });
                  
                          // on click, clear all layers
                          document.getElementById('delete').onclick = function(e) {
                              featureGroup.clearLayers();
                          }
                  
                          document.getElementById('export').onclick = function(e) {
                              // Extract GeoJson from featureGroup
                              var data = featureGroup.toGeoJSON();
                  
                              // Stringify the GeoJson
                              var convertedData = 'text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(data));
                  
                              // Create export
                              document.getElementById('export').setAttribute('href', 'data:' + convertedData);
                              document.getElementById('export').setAttribute('download', 'data.geojson');
                          }
                  
                          // Add base layers
                          L.control.layers(basemaps, overlaymaps, {
                              collapsed: true
                          }).addTo(map);
                  
                          // Fit to overlay bounds (SW and NE points with (lat, lon))
                          map.fitBounds([
                              [-18.36827062251916, -52.6871074784942],
                              [-18.35270287637126, -52.7014028427423]
                          ]);
                      </script>
                  
                  </body>
                  
                  </html>

                  ma??in.py

                  from PyQt5 import QtWebEngineWidgets, QtWidgets, QtCore
                  
                  class WebEnginePage(QtWebEngineWidgets.QWebEnginePage):
                      def __init__(self, *args, **kwargs):
                          QtWebEngineWidgets.QWebEnginePage.__init__(self, *args, **kwargs)
                          self.profile().downloadRequested.connect(self.on_downloadRequested)
                  
                      @QtCore.pyqtSlot(QtWebEngineWidgets.QWebEngineDownloadItem)
                      def on_downloadRequested(self, download):
                          old_path = download.path()
                          suffix = QtCore.QFileInfo(old_path).suffix()
                          path, _ = QtWidgets.QFileDialog.getSaveFileName(self.view(), "Save File", old_path, "*."+suffix)
                          if path:
                              download.setPath(path)
                              download.accept()
                  
                  
                  if __name__ == '__main__':
                      import sys
                  
                      sys.argv.append("--remote-debugging-port=8000")
                      sys.argv.append("--disable-web-security")
                  
                      app = QtWidgets.QApplication(sys.argv)
                      view = QtWebEngineWidgets.QWebEngineView()
                      page = WebEnginePage(view)
                      view.setPage(page)
                      path = QtCore.QDir.current().filePath("index.html")
                      view.load(QtCore.QUrl.fromLocalFile(path))
                      view.show()
                      sys.exit(app.exec_())
                  

                  <小時>

                  在你的情況下:


                  In your case:

                  self.MainWindow.webMapViewer = QtWebEngineWidgets.QWebEngineView()
                  self.MainWindow.webPageLayout.addWidget(self.MainWindow.webMapViewer)
                  page = WebEnginePage(self.MainWindow.webMapViewer) # create page
                  self.MainWindow.webMapViewer.setPage(page) # set page
                  self.html_path = os.path.split(os.path.abspath(__file__))[0] + r'/html/test.html'
                  self.MainWindow.webMapViewer.load(QtCore.QUrl().fromLocalFile(self.html_path))
                  

                  <小時>

                  加號:

                  如果要設置已定義的路線,請使用以下命令:

                  If you want to set a defined route use the following:

                  @QtCore.pyqtSlot(QtWebEngineWidgets.QWebEngineDownloadItem)
                  def on_downloadRequested(self, download):
                      directory = "/path/of/directory"
                      filename = QtCore.QFileInfo(download.path()).fileName()
                      download.setPath(QtCore.QDir(directory).filePath(filename))
                      download.accept()
                  

                  這篇關于如何使用 QWebEngineView 打開下載文件對話框?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數(shù)有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                  <tfoot id='G6Anr'></tfoot>

                  1. <legend id='G6Anr'><style id='G6Anr'><dir id='G6Anr'><q id='G6Anr'></q></dir></style></legend>
                    <i id='G6Anr'><tr id='G6Anr'><dt id='G6Anr'><q id='G6Anr'><span id='G6Anr'><b id='G6Anr'><form id='G6Anr'><ins id='G6Anr'></ins><ul id='G6Anr'></ul><sub id='G6Anr'></sub></form><legend id='G6Anr'></legend><bdo id='G6Anr'><pre id='G6Anr'><center id='G6Anr'></center></pre></bdo></b><th id='G6Anr'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='G6Anr'><tfoot id='G6Anr'></tfoot><dl id='G6Anr'><fieldset id='G6Anr'></fieldset></dl></div>

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

                          <tbody id='G6Anr'></tbody>

                          • <bdo id='G6Anr'></bdo><ul id='G6Anr'></ul>
                            主站蜘蛛池模板: 日韩一区二区三区视频 | 色婷婷综合久久久久中文一区二区 | 97热在线| 久久亚洲一区二区 | 欧美中文视频 | 久久99精品久久久 | 在线视频亚洲 | 久久精品国产久精国产 | 国产一区二区三区四区 | 中文字幕日韩在线 | 91国内精精品久久久久久婷婷 | 中文视频在线 | 狠狠爱综合| 97超碰在线播放 | 日日躁狠狠躁aaaaxxxx | 五月激情婷婷在线 | 精品久久久久久亚洲精品 | 久久亚 | 日韩久久中文字幕 | 国产一区二区三区 | 精品日韩在线 | 久久久久久av | h免费观看 | 中文日韩在线视频 | 国产精品一区二区三区在线 | 中文字幕在线网 | 日操操 | 午夜精品一区二区三区在线观看 | 精品欧美乱码久久久久久1区2区 | 久久久一区二区三区四区 | 亚洲乱码一区二区三区在线观看 | 午夜国产一级 | 精品国产一区久久 | 久久久国产视频 | 欧美激情一区 | 国产69精品久久久久777 | 成人精品免费视频 | 天天操,夜夜爽 | 福利网址| 天天操夜夜操 | 国产黄色在线观看 |