Today I will show you how to deal with events over PySide interfaces.
The main example will be the round button – QDial named roiDial and one QLCDNumber named show_lcd.
The connection come with : valueChanged.connect
This will make all changes from original and show_lcd.
If you want to deal with QDial and QLCDNumber then decorate every instance of a class-based.
Let’s see how working this example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #import python modules import sys import PySide from PySide.QtGui import * from PySide.QtCore import * #make MyWidget class from QWidget class MyWidget(QWidget): #make default __init__ def __init__(self): #take __init__ from QWidget class QWidget.__init__(self) #make roiDial from Qdial class with all definitions self.roiDial = QDial() self.roiDial.setNotchesVisible(True) self.roiDial.setMaximum(15) self.roiDial.setMinimum(1) self.roiDial.setValue(1) #make the Grid and add roiDial self.myGridLayout = QGridLayout() self.myGridLayout.addWidget(self.roiDial, 0, 0) #make show_lcd from QLCDNumber self.show_lcd = QLCDNumber() # THIS - will coonnect the named roiDial with show_lcd self.roiDial.valueChanged.connect(self.show_lcd.display) #add my show_lcd self.myGridLayout.addWidget(self.show_lcd) #make Layout and set all with my grid - myGridLayout self.setLayout(self.myGridLayout) #add one title for this window ... self.setWindowTitle("... connect !") #start the python script if __name__ =='__main__': # make one simple example with exception handling. # need to use the try - except - finally block. try: myApp = QApplication(sys.argv) myWidget = MyWidget() myWidget.show() myApp.exec_() sys.exit(0) except NameError: print("Name Error:", sys.exc_info()[1]) except SystemExit: print("Closing Window...") except Exception: print(sys.exc_info()[1]) finally: print(" - the next tutorial - ") |