PDA

View Full Version : Create own widget with graphics items - best way.



KroMagna
25th February 2011, 20:11
Hi,
I try to create widget which will represent checkers board. Widget should be resizable so all images(checkers, board) will be in svg format.
Which way to implement that is proper:
1. Inherits QGraphicsView. Set board, and checkers as QGraphicsSvgItems. Use fitInView to show the whole board.
2. Inherits QSvgWidget. Load board... and how can I place checkers on my board?
3. Inherits QWidget and try to paint on it(I don't know how already).

Are there another solutions?

stampede
25th February 2011, 20:52
Are there another solutions?
Sure, one of them is to use QGLWidget (http://doc.qt.nokia.com/latest/qglwidget.html) and do all the painting in OpenGL.

Inherits QWidget and try to paint on it(I don't know how already).
I think it's not really good way to go here. You want to simply draw few items and I assume be able to interact with them ( move ). My choice here would be option 1, because you'll have all basic functionallity already implemented - you have all the power of graphics items and scene events (mouse, keyboard, hovers) ready to be used.
Other solutions ( including mine ) will require lot more coding.
--------------------
One more thing - I'd rather subclass QGraphicsScene than QGraphicsView (or probably both ;) ), view is just for displaying the content of your scene.