PDA

View Full Version : Problem about Graphics View Framework



FinderCheng
31st October 2009, 03:33
Hi, there! I'm trying to develop a graphics editor (similar to MS Paint). For items moving I choose Graphcis View Framework to implement this software. So I have some questions:

1. How can I implement rubber with Graphics View Framework? Because each item extends QGraphicsItem, may I should override its paintEvent?

2. If I want to save the scene into a png file, how should I do?

3. How can I implement function such as eraser?

I think Graphics View Framework is much suitable for showing sonething not drawing, maybe it is more convenient with QPaint in paintEvent extends QWidget. Any suggestions are welcome!

Thank you!

wysota
31st October 2009, 08:41
I don't think QGraphicsView is a good architecture to implement a raster based painting application. The thing is you don't have objects there, you operate on the bitmap directly. Of course you can use QGraphicsView but it won't give you that many benefits. Using plain QWidget might be easier for such a simple application. If you want to go beyond Paint and implement features such as layers, etc. then graphics view might be helpful.

FinderCheng
31st October 2009, 15:09
Yeah, I plan to support layers and some processing like PS. Maybe some day later I will add CImg for editing pictures, so I choose Graphics View Framework. But it is not suitable for drawing, I think.

wysota
2nd November 2009, 18:13
But it is not suitable for drawing, I think.

Not really. At least not more than plain QWidget.

FinderCheng
3rd November 2009, 04:13
But I don't know how to do that. Should I override the paint event function? How can I implement rubberband? Override paint and mouseDragEvent or override dragEvent? Thanks!

wysota
3rd November 2009, 09:16
Should I override the paint event function?
Yes.

How can I implement rubberband?

See QRubberBand, you have an example there.