1 | from PyQt5.QtWidgets import QApplication, QMainWindow, QComboBox, QWidget |
---|
2 | from PyQt5.QtCore import pyqtSlot, pyqtSignal |
---|
3 | |
---|
4 | def int_slot(arg): |
---|
5 | print('int_slot', arg, type(arg)) |
---|
6 | |
---|
7 | def str_slot(arg): |
---|
8 | print('str_slot', arg, type(arg)) |
---|
9 | |
---|
10 | import sys |
---|
11 | app = QApplication(sys.argv) |
---|
12 | main = QMainWindow() |
---|
13 | combobox = QComboBox() |
---|
14 | |
---|
15 | main.setCentralWidget(combobox) |
---|
16 | |
---|
17 | combobox.addItems(['1', '2', '3']) |
---|
18 | |
---|
19 | # Da poslje signal integer: |
---|
20 | combobox.currentIndexChanged.connect(int_slot) |
---|
21 | # Ali istovredno |
---|
22 | combobox.currentIndexChanged[int].connect(int_slot) |
---|
23 | # Zaradi tega bo int_slot funkcija dvakrat poveyana, saj ima signal dvakrat |
---|
24 | # povezan |
---|
25 | |
---|
26 | |
---|
27 | # Ce zelimo niz ali string naredimo naslednje: |
---|
28 | combobox.currentIndexChanged[str].connect(str_slot) |
---|
29 | |
---|
30 | main.show() |
---|
31 | sys.exit(app.exec_()) |
---|