commit
ea495ed7be
7 changed files with 225 additions and 11 deletions
|
@ -15,7 +15,9 @@
|
|||
- [1.8 自定义属性测试](自定义属性测试/)
|
||||
- [1.9 自动更新](自动更新/)
|
||||
- [1.10 自定义QWidget的QSS样式](自定义QWidget的QSS样式/)
|
||||
- [1.11 浏览器获取Cookie](浏览器获取Cookie/)
|
||||
- 1.11 浏览器QWebEngine模块例子
|
||||
- [1.11 浏览器获取Cookie](浏览器获取Cookie/)
|
||||
- [1.12 浏览器下载功能](partner_625781186/6.QWebEngineView下载文件)
|
||||
- [1.12 全局热键](全局热键/)
|
||||
- [1.13 图片加载](图片加载/)
|
||||
- [1.14 窗口重启](窗口重启/)
|
||||
|
@ -46,6 +48,7 @@
|
|||
- 1.42 悬浮下拉菜单
|
||||
- [1. tableWidget形式](partner_625781186/5.hoverMenu)
|
||||
- [1.43 QListView](QListView/)
|
||||
- [1.44 QSplitter 分割条重写 来添加按钮](分割窗口的分割条重写/)
|
||||
|
||||
### [2.QGraphicsView练习](QGraphicsView练习/)
|
||||
- [2.1 世界地图](QGraphicsView练习/世界地图)
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>648</width>
|
||||
<height>493</height>
|
||||
<width>797</width>
|
||||
<height>536</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -239,7 +239,7 @@
|
|||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_19">
|
||||
<property name="text">
|
||||
<string>直通工具</string>
|
||||
<string>直通车工具工具工具</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
|
@ -309,7 +309,7 @@
|
|||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="text">
|
||||
<string>直通工具</string>
|
||||
<string>直通</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'D:\pyPro\hoverMenu\Main.ui'
|
||||
# Form implementation generated from reading ui file 'D:\QGroup_432987409\WoHowLearn\0.M_I_pyqt\partner_625781186\5.hoverMenu\Main.ui'
|
||||
#
|
||||
# Created by: PyQt5 UI code generator 5.9
|
||||
#
|
||||
|
@ -159,8 +159,8 @@ class Ui_MainWindow(object):
|
|||
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
|
||||
self.label_15.setText(_translate("MainWindow", "店铺数据"))
|
||||
self.label_16.setText(_translate("MainWindow", "竞品分析"))
|
||||
self.label_19.setText(_translate("MainWindow", "直通工具"))
|
||||
self.label_14.setText(_translate("MainWindow", "直通工具"))
|
||||
self.label_19.setText(_translate("MainWindow", "直通车工具工具工具"))
|
||||
self.label_14.setText(_translate("MainWindow", "直通"))
|
||||
self.label_17.setText(_translate("MainWindow", "个人中心"))
|
||||
self.label_18.setText(_translate("MainWindow", "退出登录"))
|
||||
self.action1.setText(_translate("MainWindow", "1"))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Project SYSTEM "Project-5.1.dtd">
|
||||
<!-- eric project file for project hoverMenu -->
|
||||
<!-- Saved: 2018-07-07, 14:22:08 -->
|
||||
<!-- Saved: 2018-07-07, 19:07:43 -->
|
||||
<!-- Copyright (C) 2018 , -->
|
||||
<Project version="5.1">
|
||||
<Language></Language>
|
||||
|
@ -44,7 +44,10 @@
|
|||
<Resource>tbqrc.qrc</Resource>
|
||||
</Resources>
|
||||
<Interfaces/>
|
||||
<Others/>
|
||||
<Others>
|
||||
<Other>Documentation</Other>
|
||||
<Other>/Documentation</Other>
|
||||
</Others>
|
||||
<Vcs>
|
||||
<VcsType>None</VcsType>
|
||||
</Vcs>
|
||||
|
@ -65,4 +68,44 @@
|
|||
<FiletypeAssociation pattern="README" type="OTHERS"/>
|
||||
<FiletypeAssociation pattern="README.*" type="OTHERS"/>
|
||||
</FiletypeAssociations>
|
||||
<Documentation>
|
||||
<DocumentationParams>
|
||||
<dict>
|
||||
<key>
|
||||
<string>ERIC4DOC</string>
|
||||
</key>
|
||||
<value>
|
||||
<dict>
|
||||
<key>
|
||||
<string>cssFile</string>
|
||||
</key>
|
||||
<value>
|
||||
<string>%PYTHON%/eric6/CSSs/default.css</string>
|
||||
</value>
|
||||
<key>
|
||||
<string>ignoreFilePatterns</string>
|
||||
</key>
|
||||
<value>
|
||||
<list>
|
||||
<string>tbqrc_rc.py</string>
|
||||
<string>Ui_Main.py</string>
|
||||
</list>
|
||||
</value>
|
||||
<key>
|
||||
<string>outputDirectory</string>
|
||||
</key>
|
||||
<value>
|
||||
<string>Documentation</string>
|
||||
</value>
|
||||
<key>
|
||||
<string>qtHelpEnabled</string>
|
||||
</key>
|
||||
<value>
|
||||
<bool>False</bool>
|
||||
</value>
|
||||
</dict>
|
||||
</value>
|
||||
</dict>
|
||||
</DocumentationParams>
|
||||
</Documentation>
|
||||
</Project>
|
||||
|
|
BIN
partner_625781186/6.QWebEngineView下载文件/ScreenShot/1.png
Normal file
BIN
partner_625781186/6.QWebEngineView下载文件/ScreenShot/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
150
partner_625781186/6.QWebEngineView下载文件/browser.py
Normal file
150
partner_625781186/6.QWebEngineView下载文件/browser.py
Normal file
|
@ -0,0 +1,150 @@
|
|||
# v1.2
|
||||
# created
|
||||
# by Roger
|
||||
# in 2017.1.3
|
||||
|
||||
from PyQt5.QtCore import *
|
||||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtWebEngineWidgets import QWebEngineView
|
||||
import configparser
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
# 设置窗口标题
|
||||
self.setWindowTitle('My Browser')
|
||||
# 设置窗口图标
|
||||
self.setWindowIcon(QIcon('icons/penguin.png'))
|
||||
|
||||
# 设置窗口大小900*600
|
||||
self.resize(750, 400)
|
||||
self.show()
|
||||
self.frame=1
|
||||
# 设置浏览器
|
||||
self.browser = MyEngineView()
|
||||
# config = configparser.ConfigParser()
|
||||
# config.readfp(open('url.ini'))
|
||||
# url= config.get("URL","url")
|
||||
url="http://www.onlinedown.net/soft/56160.htm"
|
||||
# 指定打开界面的 URL
|
||||
self.browser.setUrl(QUrl(url))
|
||||
# 添加浏览器到窗口中
|
||||
self.setCentralWidget(self.browser)
|
||||
|
||||
self.tray = QSystemTrayIcon() #创建系统托盘对象
|
||||
self.icon = QIcon('icons/back.png') #创建图标
|
||||
self.tray.setIcon(self.icon) #设置系统托盘图标
|
||||
self.tray.show()
|
||||
|
||||
|
||||
#使用QToolBar创建导航栏,并使用QAction创建按钮
|
||||
# 添加导航栏
|
||||
navigation_bar = QToolBar('Navigation')
|
||||
# 设定图标的大小
|
||||
navigation_bar.setIconSize(QSize(16, 16))
|
||||
#添加导航栏到窗口中
|
||||
self.addToolBar(navigation_bar)
|
||||
|
||||
#QAction类提供了抽象的用户界面action,这些action可以被放置在窗口部件中
|
||||
# 添加前进、后退、停止加载和刷新的按钮
|
||||
back_button = QAction(QIcon('icons/back.png'), 'Back', self)
|
||||
next_button = QAction(QIcon('icons/next.png'), 'Forward', self)
|
||||
stop_button = QAction(QIcon('icons/cross.png'), 'stop', self)
|
||||
reload_button = QAction(QIcon('icons/renew.png'), 'reload', self)
|
||||
|
||||
|
||||
back_button.triggered.connect(self.browser.back)
|
||||
next_button.triggered.connect(self.browser.forward)
|
||||
stop_button.triggered.connect(self.browser.stop)
|
||||
reload_button.triggered.connect(self.browser.reload)
|
||||
|
||||
# 将按钮添加到导航栏上
|
||||
navigation_bar.addAction(back_button)
|
||||
navigation_bar.addAction(next_button)
|
||||
navigation_bar.addAction(stop_button)
|
||||
navigation_bar.addAction(reload_button)
|
||||
#添加URL地址栏
|
||||
self.urlbar = QLineEdit()
|
||||
self.urlbar.setText(url)
|
||||
# 让地址栏能响应回车按键信号
|
||||
self.urlbar.returnPressed.connect(self.navigate_to_url)
|
||||
|
||||
navigation_bar.addSeparator()
|
||||
navigation_bar.addWidget(self.urlbar)
|
||||
|
||||
#让浏览器相应url地址的变化
|
||||
self.browser.urlChanged.connect(self.renew_urlbar)
|
||||
|
||||
def navigate_to_url(self):
|
||||
q = QUrl(self.urlbar.text())
|
||||
if q.scheme() == '':
|
||||
q.setScheme('http')
|
||||
self.browser.setUrl(q)
|
||||
|
||||
def renew_urlbar(self, q):
|
||||
# 将当前网页的链接更新到地址栏
|
||||
self.urlbar.setText(q.toString())
|
||||
self.urlbar.setCursorPosition(0)
|
||||
|
||||
class MyEngineView(QWebEngineView):
|
||||
'''
|
||||
浏览器类。
|
||||
'''
|
||||
def __init__(self, parent=None, ):
|
||||
super(MyEngineView, self).__init__(parent)
|
||||
self.parent = parent
|
||||
#有下载信号发起
|
||||
self.page().profile().downloadRequested.connect(self.on_downloadRequested)
|
||||
|
||||
def createWindow(self, type):
|
||||
'''
|
||||
实现点击跳转链接。
|
||||
'''
|
||||
return self
|
||||
|
||||
#以下函数里的 :后为注释,无实际作用
|
||||
|
||||
#下载信号连接到的槽
|
||||
def on_downloadRequested(self, download : "QWebEngineDownloadItem" ):
|
||||
# download是QWebEngineDownloadItem对象;
|
||||
download.downloadProgress.connect(self._downloadProgress)
|
||||
download.finished.connect(self._finished)
|
||||
|
||||
#下载文件的保存路径及文件名
|
||||
old_path = download.path()
|
||||
suffix = QFileInfo(old_path).suffix()
|
||||
#下载文件类型
|
||||
filttype = download.mimeType()
|
||||
#后缀切割
|
||||
unkonw_suffix = filttype.split(r'/')[-1]
|
||||
path, _ =QFileDialog.getSaveFileName(self, "Save File", old_path, "*."+unkonw_suffix + ";;" + "*."+suffix )
|
||||
|
||||
print(old_path, suffix)
|
||||
|
||||
if path!="":
|
||||
download.setPath(path)
|
||||
download.accept()
|
||||
|
||||
def _downloadProgress(self , bytesReceived:"qint64", bytesTotal:"qint64"):
|
||||
# bytesReceived 当前下载值 ; bytesTotal 文件总大小值
|
||||
self.bytesReceived = bytesReceived
|
||||
self.bytesTotal = bytesTotal
|
||||
print(bytesReceived , bytesTotal )
|
||||
|
||||
def _finished(self):
|
||||
print("下载完成")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 创建应用
|
||||
app = QApplication(sys.argv)
|
||||
# 创建主窗口
|
||||
window = MainWindow()
|
||||
# 显示窗口
|
||||
window.show()
|
||||
# 运行应用,并监听事件
|
||||
app.exec_()
|
18
partner_625781186/6.QWebEngineView下载文件/readme.md
Normal file
18
partner_625781186/6.QWebEngineView下载文件/readme.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# QWebEngineView下载文件
|
||||
|
||||
## QT官方自带例子 - 额 官方上没有 ,在本地 Examples\Qt-5.9.1\webenginewidgets\demobrowser 文件夹下。
|
||||
|
||||
![截图2](ScreenShot/1.png)
|
||||
|
||||
#QWebEngineView的下载请求信号
|
||||
QWebEngineView().page().profile().downloadRequested.connect(self.on_downloadRequested)
|
||||
|
||||
#QWebEngineDownloadItem
|
||||
下载过程的信号
|
||||
QWebEngineDownloadItem().downloadProgress.connect(self._downloadProgress)
|
||||
下载结束的信号
|
||||
QWebEngineDownloadItem().finished.connect(self._finished)
|
||||
|
||||
## 参考文献
|
||||
https://stackoverflow.com/questions/50164712/how-to-open-download-file-dialog-with-qwebengineview-on-pyqt5
|
||||
https://stackoverflow.com/questions/38812787/how-to-handle-downloads-in-qwebengine
|
Loading…
Reference in a new issue