전체 글 (69) 썸네일형 리스트형 46. 사용자 정의 시그널 46-1 예제: ex45 import sys from PyQt5.QtCore import pyqtSignal, QObject from PyQt5.QtWidgets import (QApplication, QMainWindow) class Communicate(QObject): closeApp = pyqtSignal() class MyApp(QMainWindow): def __init__(self): super().__init__() self.c = Communicate() self.initUI() def initUI(self): self.c.closeApp.connect(self.close) self.setWindowTitle('Emitting Signal') self.setGeometry(300, 300.. 45. 이벤트 핸들러(슬롯) 재구성하기2 mouseMoveEvent를 이용해서 마우스의 위치를 트래킹해서 출력해보겠습니다. 45-1 예제: ex44 import sys from PyQt5.QtGui import QMouseEvent from PyQt5.QtWidgets import (QApplication, QWidget, QLabel) class MyApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): x = 0 y = 0 self.text = 'x: {0}, y: {1}'.format(x, y) self.label = QLabel(self.text, self) self.label.move(20, 20) self.setMouseTracking(T.. 44. 이벤트 핸들러(슬롯) 재구성하기 아래와 같이 자주 쓰이는 이벤트 핸들러는 이미 만들어져 있는 경우가 많습니다. 이벤트 핸들러 설명 keyPressEvent 키보드를 눌렀을 때 동작합니다. keyReleaseEvent 키보드를 눌렀다가 뗄 때 동작합니다. mouseDoubleClickEvent 마우스를 더블클릭할 때 동작합니다. mouseMoveEvent 마우스를 움직일 때 동작합니다. mousePressEvent 마우스를 누를 때 동작합니다. mouseReleaseEvent 마우스를 눌렀다가 뗄 때 동작합니다. moveEvent 위젯이 이동할 때 동작합니다. resizeEvent 위젯의 크기를 변경할 때 동작합니다. keyPressEvent 이벤트 핸들러를 수정해서, 특정 키를 눌렀을 때 위젯을 종료하거나 최대화, 보통 크기로 조절하는.. 43. 이벤트 핸들러(슬롯) 만들기 이벤트(시그널)을 처리할 때 사용되는 함수를 이벤트 핸들러(슬롯)라고 합니다. 'Big', 'Small' 버튼을 클릭시 (시그널이 발생), 창의 크기가 바뀌도록 하는 함수(슬롯)를 정의해 보겠습니다. 43-1. 예제: ex42 import sys from PyQt5.QtWidgets import (QApplication, QWidget, QLCDNumber, QDial, QVBoxLayout, QHBoxLayout, QPushButton) class MyApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): lcd = QLCDNumber(self) dial = QDial(self) btn1 = QPushBut.. 42. 시그널과 슬롯 연결 다이얼 위젯으로 조절한 값을 화면에 출력하는 프로그램 다이얼의 값이 변할 때 발생한느 시그널이 LCD 화면에 숫자를 표시하는 슬롯과 연결됩니다. 42-1 예제: ex41 import sys from PyQt5.QtWidgets import (QApplication, QWidget, QLCDNumber, QDial, QVBoxLayout) from PyQt5.QtGui import QColor class MyApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): lcd = QLCDNumber(self) lcd.setSegmentStyle(QLCDNumber.Filled) lcd.setStyleSheet('col.. 41. QMessageBox QMessageBox Class는 사용자에게 정보를 제공하거나 어떤 동작에 확인이 필요한 경우 사용되는 대화창입니다. (QMessageBox 공식 문서) 참고 메시지 박스는 사용자에게 상황을 설명하는 기본 텍스트를 표시합니다. 그 다음 정보를 전달하거나 사용자의 의사를 묻는 텍스트를 표시할 수 있습니다. 마지막으로 더욱 자세히 상황을 설명하기 위한 세부적인 텍스트를 표시할 수 있습니다. 이러한 각각의 텍스트를 표시하기 위해 setText(), setInformativeText(), setDetailedText() 메서드를 사용할 수 있습니다. 41-1 예제: ex40 import sys from PyQt5.QtWidgets import (QApplication, QWidget, QMessageBox) c.. 40. QFileDialog QFileDialog Class는 사용자가 파일 또는 경로를 선택하고, 파일을 열어서 수정하거나 저장할 수 있게 하는 대화창입니다. (QFileDialog 공식 문서) 참고 40-1 예제: ex39 import sys from PyQt5.QtWidgets import (QApplication, QMainWindow, QTextEdit, QAction, QFileDialog) from PyQt5.QtGui import QIcon class MyApp(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.textEdit = QTextEdit() self.setCentralWidget(self.textE.. 39. QFontDialog QFontDialog Class는 Font를 선택할 수 있게 해주는 대화창입니다. (QFontDialog 공식 문서) 참고 39-1 예제: ex38 import sys from PyQt5.QtWidgets import (QApplication, QWidget, QFontDialog, QVBoxLayout, QPushButton, QSizePolicy, QLabel) """ QSizePolicy.Fixed : sizeHint()의 크기로 고정 QSizePolicy.Minimum : sizeHint() 가 minimum이 된다. 이보다 작아질 수 없음. QSizePolicy.Maximum : sizeHint() 가 maximum이 된다. 이보다 커질 수 없음. QSizePolicy.Preferred : si.. 이전 1 2 3 4 5 6 7 ··· 9 다음