반응형
signal 순서
1. 선언
2. emit
3. connect
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class signal_test(QObject):
signal1 = pyqtSignal()
def run(self):
self.signal1.emit()
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
mainsignal = signal_test()
mainsignal.signal1.connect(self.signal1_emit)
mainsignal.run()
@pyqtSlot()
def signal1_emit(self):
print("signal test")
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
결과
예제 소스
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class MySignal(QObject):
signal1 = pyqtSignal()
signal2 = pyqtSignal(int, int)
signal3 = pyqtSignal(name="testSignal")
signal4 = pyqtSignal()
signal5 = pyqtSignal(int)
signal6 = pyqtSignal(str)
x = 1234
y = 'test'
def run(self):
self.signal1.emit()
self.signal2.emit(1, 2)
self.testSignal.emit()
self.signal4.emit()
self.signal5.emit(self.x)
self.signal6.emit('TEST소문자={}'.format(self.y))
class MyWindow(QMainWindow):
def __init__(self):
super().__init__()
mysignal = MySignal()
mysignal.signal1.connect(self.signal1_emitted)
mysignal.signal2.connect(self.signal2_emitted)
mysignal.signal3.connect(self.signal3_emitted)
mysignal.signal4.connect(lambda : print("signal4 emitted"))
mysignal.signal5.connect(self.signal5_emitted)
mysignal.signal6.connect(self.signal6_emitted)
mysignal.run()
@pyqtSlot()
def signal1_emitted(self):
print("signal1 emitted")
@pyqtSlot(int, int)
def signal2_emitted(self, arg1, arg2):
print("signal2 emitted", arg1, arg2)
@pyqtSlot()
def signal3_emitted(self):
print("signal3 emitted")
@pyqtSlot(int)
def signal5_emitted(self, arg1):
print(arg1)
@pyqtSlot(str)
def signal6_emitted(self, arg1):
print(arg1)
app = QApplication(sys.argv)
window = MyWindow()
window.show()
app.exec_()
반응형
'공부 > Python' 카테고리의 다른 글
[Python] ** 의 쓰임 (0) | 2019.12.17 |
---|---|
[Python] Empty suite 에러 해결 (0) | 2019.12.12 |
3. [Python] Qt Designer 기본 소스 (0) | 2019.12.10 |
1.[Python] 기본 문법 (0) | 2019.11.27 |
1. 사용환경 설치 (0) | 2019.11.22 |