[PyQt] need drawing application demo

Mark Summerfield list at qtrac.plus.com
Thu Nov 19 14:55:58 GMT 2009


On 2009-11-19, Mitchell Model wrote:
> I am just starting to do serious work with PyQt, having used many
> other GUI/widget toolkits over the years. The rich collection of demos
> and examples included in the installation -- apparently a large subset
> of the ones in the Qt installation -- is impressive and very helpful.
> I am surprised, however, by the absence of what to me is the canonical
> demonstration, and one that I often program as my first exercise in a
> new toolkit: a small drawing program. The program should offer a
> palette of shapes (including lines), with the ability to place, move,
> resize, delete, and duplicate a shape. Optional features like
> specifying the color or size of the border and the color of the fill
> are good too. Grouping, locking, anchoring lines to shapes, and Undo/
> Redo/History would be even better.
> 
> Surely a demo like this exists somewhere? Could someone point me to
> one? (I am aware of the Diagram Scene example. It has some of what I
> am looking for, but apparently no way to resize shapes using the
> standard maneuver of grabbing a handle or corner and dragging).

With Qt you really have two different ways you can implement a drawing
program. One way is to create your own in-memory data structures and
create a QWidget subclass where you paint everything yourself. Another
way is to create a QGraphicsScene and populate it with QGraphicsItems.
Which is best rather depends on what you want to achieve, although I
think that using QGraphicsScene is easier.

I present an example that does some of the things you're talking about
in my PyQt book (chapter 13's Page Designer---in particular
pagedesigner_ans.pyw). It uses QGraphicsScene and should be easy to
extend to do all the things you mention. The book's examples can be
downloaded from my web site.

-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
	"Rapid GUI Programming with Python and Qt" - ISBN 0132354187


More information about the PyQt mailing list