1. Download and install package
Ø Eclipse download eclipse-jee-indigo-SR2-win32.zip
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/indigo/SR2/eclipse-jee-indigo-SR2-win32.zip
After download, unzip the eclipse. Eclipse noneed install
Ø Python download python-2.7.3.msi
http://www.python.org/getit/
After download, install python, I usedefault prefix C:\Python27
Ø PyQt4 download PyQt-Py2.7-x86-gpl-4.9.1-1.exe
http://www.riverbankcomputing.co.uk/software/pyqt/download/
After download, install it with the defaultprefix
2. Configure pydev in eclipse
Ø Open eclipse, select “Help”->”Install New Software…”
Ø Click Add, add pydev with http://pydev.org/updates
Ø Select “PyDev for Eclipse”, click next
Ø Select “Window”->”Preference”
Ø Add python path to interpreters.
Ø Add PyQt4 lib path to libraries. My path is C:\Python27\Lib\site-packages\PyQt4
Ø Add PyQt4 module to Forced Builtins. For modulelist, you can use “import PyQt4”, “help(PyQt4)” to get the list
3. Test environment
Create a new project, write below code
############################################
import sys
from PyQt4 import QtGui,QtCore
class MyWidget(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self,parent)
self.setFixedSize(200, 120)
self.quit = QtGui.QPushButton("Quit", self)
self.quit.setGeometry(62, 40, 75, 30)
self.quit.setFont(QtGui.QFont("Times", 18,QtGui.QFont.Bold))
self.connect(self.quit,QtCore.SIGNAL("clicked()"),
QtGui.qApp, QtCore.SLOT("quit()"))
app = QtGui.QApplication(sys.argv)
widget = MyWidget()
widget.show()
sys.exit(app.exec_())
############################################
Run it, you will see
4. A example - use QT designerfor python
Ø After install PyQt, there has a tool QT Designer which can help usto create UI
Ø Open QT Designer, create a main window
Ø Add two buttons (okButton, cancelButton), two labels and two lineEdits(nameEdit,pwEdit)
Ø Use pyuic4 to convert *.ui to *.py
c:\Python27\Lib\site-packages\PyQt4>pyuic4C:\Users\Coco\Desktop\coding\eclipse_project\PyQtSample\src\PyQtSample.ui -oc:\Users\Coco\Desktop\coding\eclipse_project\PyQtSample\src\PyQtSample.py
Ø Create a python project in eclipse, add PyQtSample.py to theproject. Create a new py file named main.py, add below line in main.py
############################
import sys
from PyQt4 import QtGui,QtCore
from PyQtSample import *
if __name__ == "__main__":
app =QtGui.QApplication(sys.argv)
mywidget = Ui_MainWindow() #you need use the class name in PyQtSampleinstead
form = QtGui.QMainWindow()
mywidget.setupUi(form)
form.show()
app.exec_()
##############################
Then you can runmain.py to check the window show out
Useful link
http://blog.donews.com/limodou/archive/category/qtpyqt
http://hi.baidu.com/buptyoyo/item/6fcf351fe8d074f164eabf29
http://blog.csdn.net/wescom/article/details/4727114
http://www.cs.usfca.edu/~afedosov/qttut/