MCPcopy Create free account
hub / github.com/PyQt5/PyQt / __init__

Method __init__

Demo/ScreenNotify.py:24–40  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

22class Window(QPlainTextEdit):
23
24 def __init__(self, *args, **kwargs):
25 super(Window, self).__init__(*args, **kwargs)
26 self.appendPlainText('修改分辨率后查看')
27 # 记录最后一次的值(减少槽调用)
28 self.m_rect = QRect()
29 # 使用定时器来延迟触发最后一次变化
30 self.m_timer = QTimer(self, timeout=self.onSolutionChanged)
31 self.m_timer.setSingleShot(True) # **重要** 保证多次信号尽量少的调用函数
32
33 # 主要是多屏幕->无屏幕->有屏幕
34 QApplication.instance().primaryScreenChanged.connect(lambda _: self.m_timer.start(1000))
35 # 其它信号最终基本上都会调用该信号
36 QApplication.instance().primaryScreen().virtualGeometryChanged.connect(
37 lambda _: self.m_timer.start(1000))
38 # DPI变化
39 QApplication.instance().primaryScreen().logicalDotsPerInchChanged.connect(
40 lambda _: self.m_timer.start(1000))
41
42 def onSolutionChanged(self):
43 # 获取主屏幕

Callers

nothing calls this directly

Calls 1

startMethod · 0.45

Tested by

no test coverage detected