Pyqt5에서 designer를 사용하여 테스트 중
1. 주모니터가 1인경우
모든 모니터 정보를 출력하면 > 주 모니터 정보를 먼저 출력함
- DISPLAY1 => DISPLAY2 순임
- 모니터1이 기준으므로 왼쪽의 모니터2는 마이너스 좌표임
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QDialog, QWidget, QDesktopWidget
from PyQt5.QtCore import Qt, QPoint
import sys
from PyQt5 import uic
form_sub = uic.loadUiType('qwin_v4_sub.ui')[0]
class myMain(QMainWindow, form_sub):
def __init__(self):
super().__init__()
self.initUI()
self.show()
def initUI(self):
self.setupUi(self)
self.getMonitorInfo()
self.center()
def getMonitorInfo(self):
# app = QApplication([])
# 현재 활성화된 모니터 정보 얻기
desktop = app.desktop()
current_screen = desktop.screenNumber(self)
screens = app.screens()
current_screen_name = screens[current_screen].name()
print("Current screen:", current_screen_name)
# 모든 모니터 정보 얻기
for screen in screens:
print("Name:", screen.name())
print("Geometry:", screen.geometry())
print("Available Geometry:", screen.availableGeometry())
# 현재 시스템 정보 가져오기
screen_count = desktop.screenCount() # 듀얼모니터 개수
print('total screens :', screen_count)
# 중앙 좌표 구하기
active_screen = desktop.screenGeometry()
center_point = active_screen.center()
# 중앙 좌표 출력하기
self.lbl_info.setText(f"Active screen center point: ({center_point.x()}, {center_point.y()})")
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
if __name__ == '__main__':
app = QApplication(sys.argv)
win = myMain()
sys.exit(app.exec_())
2. 주모니터가 2인경우
모든 모니터 정보를 출력하면 > 주 모니터 정보를 먼저 출력함
- DISPLAY2 => DISPLAY1 순임
- 왼쪽의 모니터2가 주모니터이므로 오른쪽 모니터1은 1920으로 시작함
- 주모니터(0~1919) 서브모니터(1920~3839)
- QRect는 ( x, y , width, height) 임
- 메뉴창의 세로길이가 40임
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QDialog, QWidget, QDesktopWidget
from PyQt5.QtCore import Qt, QPoint
import sys
from PyQt5 import uic
form_sub = uic.loadUiType('qwin_v4_sub.ui')[0]
class myMain(QMainWindow, form_sub):
def __init__(self ):
super().__init__()
self.initUI()
self.show()
def initUI(self):
self.setupUi(self)
self.getMonitorInfo()
self.center()
def getMonitorInfo(self):
# app = QApplication([]) # 아래에 동일한 코드가 있어 문제가 계속 발생
# 현재 활성화된 모니터 정보 얻기
desktop = app.desktop()
current_screen = desktop.screenNumber(self)
screens = app.screens()
current_screen_name = screens[current_screen].name()
print("Current screen:", current_screen_name)
# 모든 모니터 정보 얻기
for screen in screens:
print("Name:", screen.name())
print("Geometry:", screen.geometry())
print("Available Geometry:", screen.availableGeometry())
# 현재 시스템 정보 가져오기
screen_count = desktop.screenCount() # 듀얼모니터 개수
print('total screens :', screen_count)
# 중앙 좌표 구하기
active_screen = desktop.screenGeometry()
self.center_point = active_screen.center()
# 중앙 좌표 출력하기
self.lbl_info.setText(f"Active screen center point: ({self.center_point.x()}, {self.center_point.y()})")
def center(self):
qr = self.frameGeometry()
# cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(self.center_point)
self.move(qr.topLeft())
if __name__ == '__main__':
app = QApplication(sys.argv)
win = myMain()
sys.exit(app.exec_())
'PROGRAM > PyQt5 with Python' 카테고리의 다른 글
여러개의 유사한 역할을 하는 QspinBox를 하나의 함수로 처리 (0) | 2023.06.11 |
---|---|
폴더 생성하기-기존 폴더가 있으면 다음 번호로 (0) | 2023.06.07 |
원하는 폴더위치 탐색기 창으로 열기 (0) | 2023.06.07 |
3. PyQt5 시작하기 - Designer + pyuic5 이용하기 (0) | 2021.05.08 |
Import PyQt5 could not be resolved 에러 해결하기 (0) | 2021.05.07 |