Annotated PySide port of code from Mark Summerfield's 'Rapid GUI Programming with Python and Qt' (2008). The book's web site is at: http://www.qtrac.eu/pyqtbook.html.
The programs should run without mishap in your favorite Python environment, as long as you have PySide installed. It has thus far been tested on Python 2.7 in Windows 7. Unless otherwise noted, if the original name of Summerfield's script was name.pyw, the name of the adapted PySide script is namePyside.py.
Annotations include comments in code, but each chapter also contains README.md and usefulStuff.md files (the latter contains curated excerpts from PySide documentation and links from other relevant resources). When possible, we link to PySide documentation, but sometimes we have to go with Qt or PyQt when it is better.
Thanks to Mark Summerfield for encouragement, suggestions for improvement in innumerable places.
Chapter 4: Introduction to GUI Programming
Chapter 5: Dialogs
Chapter 6: Main Windows
Chapter 7: Using Qt Designer
Chapter 8: Data Handling and Custom File Formats
Chapter 9: Layouts and Multiple Documents
Chapter 10: Events, the Clipboard, and Drag and Drop
Chapter 11: Custom Widgets
Chapter 12: Item-Based Graphics
Chapter 13: Rich Text and Printing
Chapter 14: Model/View Programming
Chapter 15: Databases
Chapter 16: Advanced Model/View Programming
Chapter 17: Online Help and Internationalization
Chapter 18: Networking
Chapter 19: Multithreading
-
Follow Summerfield's recommendations for converting to Pyside, unless that would conflict with the remaining guidelines.
-
Change old-style to new-style signals and slots.
-
Replace
from PyQt4.QtCore import *
-type imports withfrom PySide import QtGui
-type imports. -
Replace
Qt.escape()
, which is not used in PySide, withxml.sax.saxutils.escape()
(see http://srinikom.github.io/pyside-bz-archive/229.html ). -
When opening files with
codecs
module, change the mode from "wt" to "w". -
Replace
QtGui.QWorkspace
(deprecated) withQtGui.QMdiArea.
This entails a great deal of other relatively minor changes (see Chapter 9 texteditor code). -
For drawpolygon to work (Chapter 11) change list of numbers to list of QPoints. For instance, change: drawPolygon(QtGui.QPolygon([x1, y1, x2, y2])) to: drawPolygon(QtGui.QPolygon([QtCore.QPoint(x1, y1), QtCore.QPoint(x2,y2)]))
-
Replace deprecated
QMatrix
and.matrix()
with 'QTransform' and '.transform()` (Chapter 12). -
Replace the single line:
self.assetView.selectionModel().currentRowChanged.connect(self.assetChanged)
With the two lines:
selectionModel = self.assetView.selectionModel()
selectionModel.currentRowChanged.connect(self.assetChanged)
This seems to be due to a bug in PySide (Chapter 15).
-
Get sqlite to work by adding:
site_pack_path = site.getsitepackages()[1] QtGui.QApplication.addLibraryPath('{0}\\PySide\\plugins'.format(site_pack_path))
Before QtSql.QSqlDatabase.adDatabase("QSQLITE")
. Be sure to import site
. Not sure how platform-dependent this problem is. (Chapter 15)
-
Replace obsolete
Qt.TextColorRole
withQt.ForegroundRole
. -
Replace
.toPyDateTime()
with.toPython()
-
For Chapter 17, to get the *_fr.html pages to show up in the help pages, add:
QtCore.QLocale.setDefault(QtCore.QLocale(locale))
Where 'locale' is the value entered by the user at the command line. Note this may not be required on all systems. I needed it in Python 2.7.6, Qt 4.8.4, PySide 1.2.1 on Windows 7.
-
Replace
isAlive(qObj)
function, which uses sip, with:from Shiboken import shiboken def isAlive(qObj): return shiboken.isValid(qObj)
If you get the error that shiboken is not installed, in Windows command line:
pip install --use-wheel -U shiboken
Not sure what to do in Linux/Mac.
- At least in the first few chapters, we replace 'super' with explicit base class initialization, just to try it both ways (see http://stackoverflow.com/questions/23981625/why-is-super-used-so-much-in-pyside-pyqt).
PySideSummer is under the GPL license (http://www.gnu.org/copyleft/gpl.html)