forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreenNotify.py
58 lines (49 loc) · 2.26 KB
/
ScreenNotify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2021/4/13
@author: Irony
@site: https://github.com/PyQt5
@email: [email protected]
@file: ScreenNotify
@description: 屏幕、分辨率、DPI变化通知
"""
import sys
from PyQt5.QtCore import QTimer, QRect
from PyQt5.QtWidgets import QApplication, QPlainTextEdit, qApp
class Window(QPlainTextEdit):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.appendPlainText('修改分辨率后查看')
# 마지막 값을 기록하십시오 (슬롯 줄이기).
self.m_rect = QRect()
# 타이머를 사용하여 트리거 마지막 변경 지연
self.m_timer = QTimer(self, timeout=self.onSolutionChanged)
self.m_timer.setSingleShot(True) # ** 중요 ** 보증 다중 신호가 작은 통화 기능으로
# 주로 다중 화면 -> 화면 없음 -> 화면이있는
qApp.primaryScreenChanged.connect(lambda _: self.m_timer.start(1000))
# 다른 신호는 결국이 신호를 호출합니다
qApp.primaryScreen().virtualGeometryChanged.connect(lambda _: self.m_timer.start(1000))
#dpi 변경
qApp.primaryScreen().logicalDotsPerInchChanged.connect(lambda _: self.m_timer.start(1000))
def onSolutionChanged(self):
# 홈 화면을 얻으십시오
screen = qApp.primaryScreen()
if self.m_rect == screen.availableVirtualGeometry():
return
self.m_rect = screen.availableVirtualGeometry()
# 모든 화면을 사용할 수 있습니다
self.appendPlainText('\navailableVirtualGeometry: {0}'.format(str(screen.availableVirtualGeometry())))
# 모든 화면을 얻으십시오
screens = qApp.screens()
for screen in screens:
self.appendPlainText(
'screen: {0}, geometry({1}), availableGeometry({2}), logicalDotsPerInch({3}), '
'physicalDotsPerInch({4}), refreshRate({5})'.format(
screen.name(), screen.geometry(), screen.availableGeometry(), screen.logicalDotsPerInch(),
screen.physicalDotsPerInch(), screen.refreshRate()))
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())