PyQt / Development with Eric 3¶
Legacy Wiki Page
This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.
Add your tips on eric3 here!
This is a little tutorial that is a bit outdated (the sample source has to be changed in some points, but I donât remember them, sorry): http://www.pycs.net/lateral/stories/16.html
OK, here is the 5-minute introduction. Iâve just installed eric3 and pyQt on debian; the command
apt-get install eric eric-api-files pyqt-tools
will do the trick.
On Ubuntu, âapt-get install ericâ is sufficient. Just to be sure, you can try
apt-get install eric python-kde3 qt3-assistant qt3-designer qt3-linguist qt3-doc pyqt-tools python-xml
which will install eric and all the optional packages that it requires.
Then, a very important thing to do is to set up QTDIR correctly in Settings->Preferences->Qt or else a lot of problems will crop out later. Iâve mine set to /usr/share/qt3
Restart eric and everything (hopefully) will work as explained belowâŠ
Create_Project¶
First, select Project->New to create a new project. Name it âHelloâ, ensure that the UI Type is QT, and press OK.
Create_Dialog¶
Run Qt Designer (Extras->Tools->Designer) and create a new form using File->New⊠and selecting Dialog from the wizard.
Set the name of the dialog form hello_form and change the caption to âhelloâ (or whatever). Add a PushButton to the form and the change the text to âCloseâ (or, again, whatever).
Hit F3 or the Connect Signals/Slots button. Create a connection from the PushButton pressed signal to the hello_form âclose()â slot.
Save the form as hello_form.ui and exit Qt designer.
Add Dialog To Project¶
The project Browser is the tabbed or notebook widget in on the upper left of the Eric3 IDE. It has a tab with a snake, a (drawing) compass, a fish, a piece of paper saying IDL, and a blank piece of paper; these represent the project Sources, Forms, Translations, Interfaces, and Others.
Go to the Forms tab in the Project Browser. Right-click on the tab to get the Forms context menu ; select âNew Formâ, then âDialogâ . When the file dialog comes up, select âhello_form.uiâ and press OK.
The âhello_form.uiâ file will appear in the Forms tab. Right-click on it and select âCompile Formâ . This will create âhello_form.pyâ and add it to the Sources tab in the Project Browser.
Generate Subclass For Form¶
Right-click on âhello_form.uiâ in the Forms tab of the Project Browser and choose âGenerate Subclassâ . When prompted for a name, enter âhello_form_implâ.
This will open an untitled python script window with the subclass implementation in it. Save the script as âhello_form_impl.pyâ .
Go to the Sources tab of the Project Browser and right-click on the background. Choose âAdd source fileâŠâ and select âhello_form_impl.pyâ in the file dialog, then press OK.
Create A Main Script¶
Open a new python script. Enter the following code:
1 #!/usr/bin/env python
2
3 import sys
4 from qt import *
5 from hello_form_impl import hello_form_Impl
6
7 # create Qt application
8 app = QApplication(sys.argv)
9
10 # create and show Qt form
11 form = hello_form_Impl()
12 form.show()
13
14 # enter Qt event-handling loop
15 app.exec_loop()
Save the script as âhello_main.pyâ
Go to Project->Properties
Set the âMain scriptâ property to âhello_main.pyâ and press OK; this will add âhello_main.pyâ to the Sources tab of the Project Browser.
Wrapping It Up¶
Use Debug->Run Project to run the scripts and show the dialog.