QGraphicsItem subclass access to QGraphicsView size
Hi,
I would like to draw an arrow inside a QGraphicsScene linked to a QGraphicsview, but the arrow needs to reach from the left-bottom of the view to the right-bottom of the view. It also needs to move and stay +/- 10 pixels above the bottom. It should always be in view, but resize only one line (no transformation).
Something like this:
|-------------------->|
resized:
|---------------------------------------->|
note the arrow pointer thing (>) has not changed size.
It almost seems like I need to make a QPainterPath with three lineTo's and one moveTo, where one lineTo is subject to normal transformation, but the rest isn't.
My conclusion would be QPainterPath isn't what I'm looking for; maybe a QList<QGrapicsLineItem> is what I need. What do you think?
Thanks
Re: QGraphicsItem subclass access to QGraphicsView size
if only need to draw a arrow in the top of the view is more simple subclass a view and draw the arrow in the drawForeground() function
Code:
{
public:
explicit CustomView
( QWidget * parent
= 0 )
protected:
{
painter
->setPen
(QPen(Qt
::red,
3));
painter->drawLine( rect.topLeft(), rect.bottomRight() );
painter->drawLine( rect.topRight(), rect.bottomLeft() );
}
};
this draw a big X in the view.
convert the code to draw a arrow must be trivial. but is late and i want to sleep
Re: QGraphicsItem subclass access to QGraphicsView size
That looks like a good idea, that way I won't have to worry about getting parent widget coordinates.
One question though: will it be possible to "print" the whole scene (including the arrows) to an image, or will the arrow not be included because it's not part of the scene?
Thanks!
Re: QGraphicsItem subclass access to QGraphicsView size
Note to self, must read docs:
http://doc.trolltech.com/4.2/qgraphicsview.html#render
It is the view that is rendered to the printer, not the scene, so drawing on the foreground it is!
thanks again
Re: QGraphicsItem subclass access to QGraphicsView size