PDA

View Full Version : How can I implement rubber-band with graphics view items?



FinderCheng
7th November 2009, 11:30
Hi, guys! I'm trying to develop a graphics software just like Photoshop with multi-layer so I choose Graphcis View Framework. But I have a problem about drawing rubber-band using Graphics View Framework.
I have some tools like draw a line, draw a rectangle and so on, implemented by view items. I don't know how to implement rubber-band with these items. It seems I should override paint function, take QGraphicsLineItem's subclass for example, there are two fields, startPoint and endPoint, and QPainter.drawLine(startPoint, endPoint) in paint function, but when should I invoke this function? And what's the option parameter when I call it? I assign these two points in mouse event functions of a subclass of QGraphicsScene, am I right?
Thank you all for giving me suggestions!

prashant
8th November 2009, 06:58
Check this:
http://doc.trolltech.com/4.5/qgraphicsview.html#dragMode-prop (QGraphicsView.setDragMode (self, DragMode mode))
and you have three types of drag mode supported including rubber band selection mode.

To find out if an item is selected by clicking it or when it comes under rubber band selection region you can use this condition in paint event:


if (option->state & QStyle::State_Selected) {
// draw a rectangle around selected object

aamer4yu
8th November 2009, 09:45
Check out the 40000 chips demo example in Qt Demos-->Demonstrations.
They have a rubberband implementation.

FinderCheng
8th November 2009, 16:25
I'm sorry. Maybe I asked a wrong question. My question is how to draw an item, such as a line, say a rubber line. That is when I clicked the scene, I get the start point and then I drag mouse the end point moves, too, and the I release mouse button, the line draw finally. This is the rubber-line in CG, not select areas.
I know I can implement it with XOR in OpenGL or try to draw on buffer image first then update this buffer. This can be done easily with paint event function. But I don't know how to get this feature with Graphics View Framework's items. And how can I use XOR mode in Qt4 if I must use XOR?
But still thank you all!

aamer4yu
9th November 2009, 04:21
In that case still have a look at Qt Demos-->GraphicsView-->Diagram Scene (http://doc.trolltech.com/4.6-snapshot/graphicsview-diagramscene.html) example.
There is line to connect between the objects, and I guess you looking for that kind of implementation.

FinderCheng
9th November 2009, 05:37
Yeah! It seems that is suitable for me! I'll read it to find any solution. Thank you!

mishra.rakesh510
14th February 2013, 12:01
Hi,
I am not able to get your link could you please help me.
"Qt Demos-->GraphicsView-->Diagram Scene"
Thanks
Rakesh