Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b95c424c3e
9 changed files with 276 additions and 1 deletions
|
@ -4,7 +4,9 @@ encoding//Demo/CircleLine.py=utf-8
|
||||||
encoding//Demo/EmbedWindow.py=utf-8
|
encoding//Demo/EmbedWindow.py=utf-8
|
||||||
encoding//Demo/FacePoints.py=utf-8
|
encoding//Demo/FacePoints.py=utf-8
|
||||||
encoding//Demo/FollowWindow.py=utf-8
|
encoding//Demo/FollowWindow.py=utf-8
|
||||||
|
encoding//Demo/FramelessDialog.py=utf-8
|
||||||
encoding//Demo/FramelessWindow.py=utf-8
|
encoding//Demo/FramelessWindow.py=utf-8
|
||||||
|
encoding//Demo/IsSignalConnected.py=utf-8
|
||||||
encoding//Demo/Lib/Application.py=utf-8
|
encoding//Demo/Lib/Application.py=utf-8
|
||||||
encoding//Demo/Lib/FramelessWindow.py=utf-8
|
encoding//Demo/Lib/FramelessWindow.py=utf-8
|
||||||
encoding//Demo/NativeEvent.py=utf-8
|
encoding//Demo/NativeEvent.py=utf-8
|
||||||
|
@ -13,6 +15,7 @@ encoding//Demo/ProbeWindow.py=utf-8
|
||||||
encoding//Demo/QtThreading.py=utf-8
|
encoding//Demo/QtThreading.py=utf-8
|
||||||
encoding//Demo/RestartWindow.py=utf-8
|
encoding//Demo/RestartWindow.py=utf-8
|
||||||
encoding//Demo/SharedMemory.py=utf-8
|
encoding//Demo/SharedMemory.py=utf-8
|
||||||
|
encoding//Demo/ShowFrameWhenDrag.py=utf-8
|
||||||
encoding//Demo/SingleApplication.py=utf-8
|
encoding//Demo/SingleApplication.py=utf-8
|
||||||
encoding//Demo/VerificationCode.py=utf-8
|
encoding//Demo/VerificationCode.py=utf-8
|
||||||
encoding//Demo/WeltHideWindow.py=utf-8
|
encoding//Demo/WeltHideWindow.py=utf-8
|
||||||
|
|
85
Demo/FramelessDialog.py
Normal file
85
Demo/FramelessDialog.py
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Created on 2019年4月19日
|
||||||
|
@author: Irony
|
||||||
|
@site: https://pyqt5.com https://github.com/892768447
|
||||||
|
@email: 892768447@qq.com
|
||||||
|
@file: FramelessDialog
|
||||||
|
@description: 无边框圆角对话框
|
||||||
|
"""
|
||||||
|
from PyQt5.QtCore import Qt, QSize, QTimer
|
||||||
|
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QWidget,\
|
||||||
|
QGraphicsDropShadowEffect, QPushButton, QGridLayout, QSpacerItem,\
|
||||||
|
QSizePolicy
|
||||||
|
|
||||||
|
|
||||||
|
__Author__ = "Irony"
|
||||||
|
__Copyright__ = 'Copyright (c) 2019 Irony'
|
||||||
|
__Version__ = 1.0
|
||||||
|
|
||||||
|
Stylesheet = """
|
||||||
|
#Custom_Widget {
|
||||||
|
background: white;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#closeButton {
|
||||||
|
min-width: 36px;
|
||||||
|
min-height: 36px;
|
||||||
|
font-family: "Webdings";
|
||||||
|
qproperty-text: "r";
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
#closeButton:hover {
|
||||||
|
color: white;
|
||||||
|
background: red;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Dialog(QDialog):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(Dialog, self).__init__(*args, **kwargs)
|
||||||
|
self.setObjectName('Custom_Dialog')
|
||||||
|
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
|
||||||
|
self.setAttribute(Qt.WA_TranslucentBackground, True)
|
||||||
|
self.setStyleSheet(Stylesheet)
|
||||||
|
self.initUi()
|
||||||
|
# 添加阴影
|
||||||
|
effect = QGraphicsDropShadowEffect(self)
|
||||||
|
effect.setBlurRadius(12)
|
||||||
|
effect.setOffset(0, 0)
|
||||||
|
effect.setColor(Qt.gray)
|
||||||
|
self.setGraphicsEffect(effect)
|
||||||
|
|
||||||
|
def initUi(self):
|
||||||
|
layout = QVBoxLayout(self)
|
||||||
|
# 重点: 这个widget作为背景和圆角
|
||||||
|
self.widget = QWidget(self)
|
||||||
|
self.widget.setObjectName('Custom_Widget')
|
||||||
|
layout.addWidget(self.widget)
|
||||||
|
|
||||||
|
# 在widget中添加ui
|
||||||
|
layout = QGridLayout(self.widget)
|
||||||
|
layout.addItem(QSpacerItem(
|
||||||
|
40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum), 0, 0)
|
||||||
|
layout.addWidget(QPushButton(
|
||||||
|
'r', self, clicked=self.accept, objectName='closeButton'), 0, 1)
|
||||||
|
layout.addItem(QSpacerItem(20, 40, QSizePolicy.Minimum,
|
||||||
|
QSizePolicy.Expanding), 1, 0)
|
||||||
|
|
||||||
|
def sizeHint(self):
|
||||||
|
return QSize(600, 400)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
w = Dialog()
|
||||||
|
w.exec_()
|
||||||
|
QTimer.singleShot(200, app.quit)
|
||||||
|
sys.exit(app.exec_())
|
63
Demo/IsSignalConnected.py
Normal file
63
Demo/IsSignalConnected.py
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Created on 2019年2月24日
|
||||||
|
@author: Irony
|
||||||
|
@site: https://pyqt5.com https://github.com/892768447
|
||||||
|
@email: 892768447@qq.com
|
||||||
|
@file: IsSignalConnected
|
||||||
|
@description: 判断信号是否连接
|
||||||
|
"""
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QTextBrowser
|
||||||
|
|
||||||
|
|
||||||
|
__Author__ = """By: Irony
|
||||||
|
QQ: 892768447
|
||||||
|
Email: 892768447@qq.com"""
|
||||||
|
__Copyright__ = 'Copyright (c) 2019 Irony'
|
||||||
|
__Version__ = 1.0
|
||||||
|
|
||||||
|
|
||||||
|
class Window(QWidget):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(Window, self).__init__(*args, **kwargs)
|
||||||
|
layout = QVBoxLayout(self)
|
||||||
|
self.button1 = QPushButton('已连接', self, clicked=self.doTest)
|
||||||
|
self.button2 = QPushButton('未连接', self)
|
||||||
|
self.retView = QTextBrowser(self)
|
||||||
|
layout.addWidget(self.button1)
|
||||||
|
layout.addWidget(self.button2)
|
||||||
|
layout.addWidget(self.retView)
|
||||||
|
|
||||||
|
def doTest(self):
|
||||||
|
self.retView.append("""
|
||||||
|
# button1 clicked 是否连接: %s
|
||||||
|
# button2 clicked 是否连接: %s
|
||||||
|
""" % (
|
||||||
|
self.isSignalConnected(self.button1, 'clicked()'),
|
||||||
|
self.isSignalConnected(self.button2, 'clicked()')
|
||||||
|
))
|
||||||
|
|
||||||
|
def isSignalConnected(self, obj, name):
|
||||||
|
"""判断信号是否连接
|
||||||
|
:param obj: 对象
|
||||||
|
:param name: 信号名,如 clicked()
|
||||||
|
"""
|
||||||
|
index = obj.metaObject().indexOfMethod(name)
|
||||||
|
if index > -1:
|
||||||
|
method = obj.metaObject().method(index)
|
||||||
|
if method:
|
||||||
|
return obj.isSignalConnected(method)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
w = Window()
|
||||||
|
w.show()
|
||||||
|
sys.exit(app.exec_())
|
|
@ -17,6 +17,9 @@
|
||||||
- [人脸特征点](#15、人脸特征点)
|
- [人脸特征点](#15、人脸特征点)
|
||||||
- [使用Threading](#16、使用Threading)
|
- [使用Threading](#16、使用Threading)
|
||||||
- [背景连线动画](#17、背景连线动画)
|
- [背景连线动画](#17、背景连线动画)
|
||||||
|
- [无边框圆角对话框](#18、无边框圆角对话框)
|
||||||
|
- [调整窗口显示边框](#19、调整窗口显示边框)
|
||||||
|
- [判断信号是否连接](#20、判断信号是否连接)
|
||||||
|
|
||||||
## 1、重启窗口Widget
|
## 1、重启窗口Widget
|
||||||
[运行 RestartWindow.py](RestartWindow.py)
|
[运行 RestartWindow.py](RestartWindow.py)
|
||||||
|
@ -170,4 +173,33 @@ PyQt 结合 Opencv 进行人脸检测;
|
||||||
|
|
||||||
主要参考 [背景连线动画.html](Data/背景连线动画.html)
|
主要参考 [背景连线动画.html](Data/背景连线动画.html)
|
||||||
|
|
||||||
![CircleLine](ScreenShot/CircleLine.gif)
|
![CircleLine](ScreenShot/CircleLine.gif)
|
||||||
|
|
||||||
|
|
||||||
|
## 18、无边框圆角对话框
|
||||||
|
[运行 FramelessDialog.py](FramelessDialog.py)
|
||||||
|
|
||||||
|
1. 通过设置 `self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)` 和 `self.setAttribute(Qt.WA_TranslucentBackground, True)` 达到无边框和背景透明
|
||||||
|
2. 在QDialog中放置一个QWidget作为背景和圆角
|
||||||
|
3. 在QWidget中放置其他内容
|
||||||
|
|
||||||
|
![FramelessDialog](ScreenShot/FramelessDialog.png)
|
||||||
|
|
||||||
|
## 19、调整窗口显示边框
|
||||||
|
[运行 ShowFrameWhenDrag.py](ShowFrameWhenDrag.py)
|
||||||
|
|
||||||
|
1. 全局设置是【】在控制面板中->调整Windows的外观和性能->去掉勾选 拖动时显示窗口内容】
|
||||||
|
2. 但是为了不影响其它应用,可以在窗口处理函数wndproc中对其进行判断处理
|
||||||
|
3. 必须先要替换wndproc为自己的函数
|
||||||
|
4. 当消息事件==WM_NCLBUTTONDOWN的时候, 先强制开启,然后处理完成后再还原
|
||||||
|
|
||||||
|
好处在于可以减少窗口更新的次数(用途有频繁渲染的界面)
|
||||||
|
|
||||||
|
![ShowFrameWhenDrag](ScreenShot/ShowFrameWhenDrag.gif)
|
||||||
|
|
||||||
|
## 20、判断信号是否连接
|
||||||
|
[运行 IsSignalConnected.py](IsSignalConnected.py)
|
||||||
|
|
||||||
|
通过 `isSignalConnected` 判断是否连接
|
||||||
|
|
||||||
|
![IsSignalConnected](ScreenShot/IsSignalConnected.png)
|
BIN
Demo/ScreenShot/FramelessDialog.png
Normal file
BIN
Demo/ScreenShot/FramelessDialog.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
BIN
Demo/ScreenShot/IsSignalConnected.png
Normal file
BIN
Demo/ScreenShot/IsSignalConnected.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.4 KiB |
BIN
Demo/ScreenShot/ShowFrameWhenDrag.gif
Normal file
BIN
Demo/ScreenShot/ShowFrameWhenDrag.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
89
Demo/ShowFrameWhenDrag.py
Normal file
89
Demo/ShowFrameWhenDrag.py
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Created on 2019年4月23日
|
||||||
|
@author: Irony
|
||||||
|
@site: https://pyqt5.com https://github.com/892768447
|
||||||
|
@email: 892768447@qq.com
|
||||||
|
@file: ShowFrameWhenDrag
|
||||||
|
@description: 调整窗口显示边框
|
||||||
|
"""
|
||||||
|
from ctypes import sizeof, windll, c_int, byref, c_long, c_void_p, c_ulong, c_longlong,\
|
||||||
|
c_ulonglong, WINFUNCTYPE, c_uint
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel
|
||||||
|
|
||||||
|
|
||||||
|
__Author__ = 'Irony'
|
||||||
|
__Copyright__ = 'Copyright (c) 2019 Irony'
|
||||||
|
__Version__ = 1.0
|
||||||
|
|
||||||
|
if sizeof(c_long) == sizeof(c_void_p):
|
||||||
|
WPARAM = c_ulong
|
||||||
|
LPARAM = c_long
|
||||||
|
elif sizeof(c_longlong) == sizeof(c_void_p):
|
||||||
|
WPARAM = c_ulonglong
|
||||||
|
LPARAM = c_longlong
|
||||||
|
|
||||||
|
WM_NCLBUTTONDOWN = 0x00a1
|
||||||
|
GWL_WNDPROC = -4
|
||||||
|
SPI_GETDRAGFULLWINDOWS = 38
|
||||||
|
SPI_SETDRAGFULLWINDOWS = 37
|
||||||
|
WNDPROC = WINFUNCTYPE(c_long, c_void_p, c_uint, WPARAM, LPARAM)
|
||||||
|
|
||||||
|
try:
|
||||||
|
CallWindowProc = windll.user32.CallWindowProcW
|
||||||
|
SetWindowLong = windll.user32.SetWindowLongW
|
||||||
|
SystemParametersInfo = windll.user32.SystemParametersInfoW
|
||||||
|
except:
|
||||||
|
CallWindowProc = windll.user32.CallWindowProcA
|
||||||
|
SetWindowLong = windll.user32.SetWindowLongA
|
||||||
|
SystemParametersInfo = windll.user32.SystemParametersInfoA
|
||||||
|
|
||||||
|
|
||||||
|
def GetDragFullwindows():
|
||||||
|
rv = c_int()
|
||||||
|
SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, byref(rv), 0)
|
||||||
|
return rv.value
|
||||||
|
|
||||||
|
|
||||||
|
def SetDragFullwindows(value):
|
||||||
|
SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, value, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
class Window(QWidget):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(Window, self).__init__(*args, **kwargs)
|
||||||
|
layout = QVBoxLayout(self)
|
||||||
|
layout.addWidget(QLabel('拖动或者调整窗口试试看'))
|
||||||
|
|
||||||
|
# 重点替换窗口处理过程
|
||||||
|
self._newwndproc = WNDPROC(self._wndproc)
|
||||||
|
self._oldwndproc = SetWindowLong(
|
||||||
|
int(self.winId()), GWL_WNDPROC, self._newwndproc)
|
||||||
|
|
||||||
|
def _wndproc(self, hwnd, msg, wparam, lparam):
|
||||||
|
if msg == WM_NCLBUTTONDOWN:
|
||||||
|
# 获取系统本身是否已经开启
|
||||||
|
isDragFullWindow = GetDragFullwindows()
|
||||||
|
if isDragFullWindow != 0:
|
||||||
|
# 开启虚线框
|
||||||
|
SetDragFullwindows(0)
|
||||||
|
# 系统本身处理
|
||||||
|
ret = CallWindowProc(
|
||||||
|
self._oldwndproc, hwnd, msg, wparam, lparam)
|
||||||
|
# 关闭虚线框
|
||||||
|
SetDragFullwindows(1)
|
||||||
|
return ret
|
||||||
|
return CallWindowProc(self._oldwndproc, hwnd, msg, wparam, lparam)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
w = Window()
|
||||||
|
w.show()
|
||||||
|
sys.exit(app.exec_())
|
|
@ -167,7 +167,9 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
|
||||||
- [简单的窗口贴边隐藏](Demo/WeltHideWindow.py)
|
- [简单的窗口贴边隐藏](Demo/WeltHideWindow.py)
|
||||||
- [嵌入外部窗口](Demo/EmbedWindow.py)
|
- [嵌入外部窗口](Demo/EmbedWindow.py)
|
||||||
- [简单跟随其它窗口](Demo/FollowWindow.py)
|
- [简单跟随其它窗口](Demo/FollowWindow.py)
|
||||||
|
- [调整窗口显示边框](Demo/ShowFrameWhenDrag.py)
|
||||||
- [简单探测窗口和放大截图](Demo/ProbeWindow.py)
|
- [简单探测窗口和放大截图](Demo/ProbeWindow.py)
|
||||||
|
- [无边框圆角对话框](Demo/FramelessDialog.py)
|
||||||
- [无边框自定义标题栏窗口](Demo/FramelessWindow.py)
|
- [无边框自定义标题栏窗口](Demo/FramelessWindow.py)
|
||||||
- [右下角弹出框](Demo/WindowNotify.py)
|
- [右下角弹出框](Demo/WindowNotify.py)
|
||||||
- [程序重启](Demo/AutoRestart.py)
|
- [程序重启](Demo/AutoRestart.py)
|
||||||
|
@ -180,6 +182,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
|
||||||
- [人脸特征点](Demo/FacePoints.py)
|
- [人脸特征点](Demo/FacePoints.py)
|
||||||
- [使用Threading](Demo/QtThreading.py)
|
- [使用Threading](Demo/QtThreading.py)
|
||||||
- [背景连线动画](Demo/CircleLine.py)
|
- [背景连线动画](Demo/CircleLine.py)
|
||||||
|
- [判断信号是否连接](Demo/IsSignalConnected.py)
|
||||||
|
|
||||||
# QQ群
|
# QQ群
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue