Paint in PyQt — one of the 15 Minute Apps


#1

Working on expanding the “Create Simple GUI Applications” course I wanted some more example applications to work with — to go beyond what the web browser example can do. So I sat down and wrote a bunch of demo slightly-basic slightly-rubbish apps over a week or so.

There are 15 in total, and I called it “15 minute apps” … the “minute” is small but is intended as a play on words for Jamie’s Olivers “15 Minute Meals”, since neither take 15 minutes to create.

(This isn’t as funny once you have to write it out.)

One of my favourites is Paint — actually “Piecasso” — which features a pie-based image stamper tool. This is a pretty complex app to make in PyQt using a lot of event redirection.


#2

Which Qt widget are you using for the canvas? Is this a QGraphicsScene?


#3

The drawing is actually done on a QLabel. It’s a bit of a peculiarity about Qt is that there is no bitmap widget you can use out of the box. But QLabel has the ability to show a custom QPixmap object on itself, so you can use that to draw on.

The downside is that it doesn’t really handle scaling, scrolling, etc. particularly gracefully. Could probably put together a custom widget to handle that which wraps QLabel though.