PyQt/QWebView/DreamTree.py

68 lines
1.9 KiB
Python
Raw Normal View History

2017-04-07 09:20:04 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2021-07-13 14:52:26 +08:00
"""
2017-04-07 09:20:04 +08:00
Created on 2017年4月6日
2021-07-13 14:52:26 +08:00
@author: Irony
@site: https://pyqt.site , https://github.com/PyQt5
2017-04-07 09:20:04 +08:00
@email: 892768447@qq.com
@file: DreamTree
@description:
2021-07-13 14:52:26 +08:00
"""
2017-04-07 09:20:04 +08:00
import sys
from PyQt5.QtCore import Qt, QUrl
from PyQt5.QtGui import QPalette
from PyQt5.QtWebKitWidgets import QWebView
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout
# from PyQt5.QtWebKit import QWebSettings
2018-12-26 23:04:56 +08:00
2017-04-07 09:20:04 +08:00
# 要实现透明的webview,需要先用一个QWidget作为父控件
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.setAttribute(Qt.WA_TranslucentBackground, True) # 设置父控件Widget背景透明
self.setWindowFlags(Qt.FramelessWindowHint) # 去掉边框
palette = self.palette()
palette.setBrush(QPalette.Base, Qt.transparent) # 父控件背景透明
self.setPalette(palette)
layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
2018-12-26 23:04:56 +08:00
# QWebSettings.globalSettings().setAttribute(
# QWebSettings.DeveloperExtrasEnabled, True)# web开发者工具
2017-04-07 09:20:04 +08:00
self.webView = QWebView(self) # 网页控件
layout.addWidget(self.webView)
self.webView.setContextMenuPolicy(Qt.NoContextMenu) # 去掉右键菜单
self.mainFrame = self.webView.page().mainFrame()
self.mainFrame.setScrollBarPolicy(
Qt.Vertical, Qt.ScrollBarAlwaysOff) # 去掉滑动条
self.mainFrame.setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
# 最大化
rect = app.desktop().availableGeometry()
self.resize(rect.size())
self.webView.resize(rect.size())
def load(self):
self.webView.load(QUrl('qrc:/tree.html')) # 加载网页
2018-12-26 23:04:56 +08:00
2017-04-07 09:20:04 +08:00
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Window()
w.show()
w.load()
sys.exit(app.exec_())