Blog Archives

PyQt4: Getting into depth

Now let us add some functionalities to the window generated. For that, I am listing the APIs to create any widget and handling signals & slots:

To create any widget:

1. textbox=QtGui.QTextBox(“content of the text box”)

Note:This will work fine unless until you need to access this textbox in some function treating it as a global variable. To avoid the errors in future, use this line:

self.textbox=QtGui.QTextBox(“content of the text box”)

adding self in beginning will make textbox an attribute of the window under which it is created.

2. self.label=QtGui.QLabel(“content of the label”)

3. self.pushbutton=QtGui.QPushButton(“text on pushbutton”)

to create singnals and slots:

This can be achieved in two ways:
1.New version API- QtCore.QObject.Connect method:
QtCore.QObject.Connect(<name of the object generating signal>,QtCore.SIGNAL(“<signal name>”), <slot>)


QtCore.QObject.Connect(self.pushbutton,QtCore.SIGNAL(“clicked()”),   self.on_pushbutton_click) Read the rest of this entry