PDA

View Full Version : Problem painting lines



jano_alex_es
25th June 2009, 11:37
Hi,

I'd like to paint, into a scene, some lines connected with one of the Join Style available in QPen definition.

the next code:



QPen myPen(brush,10,Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);

my_scene->addLine(QLineF(QPointF(0,0), QPointF(100, 0)), myPen);
my_scene->addLine(QLineF(QPointF(100,0), QPointF(100, 100)), myPen);


doesn't show that join style (logically). So I started with QGraphicsPathItem ----> QPainterPath, where the function "addQLineF" does not exist.

How I can paint, in a scene, my lines joined with the pen's join style?

thanks!

wysota
25th June 2009, 11:42
QPainterPath::lineTo() and QPainter::drawLines() in general.

jano_alex_es
25th June 2009, 12:04
I'm working with a scene (I need to create items as well)... will I have any incompatibility if I start to paint forms in screen with a QPainter? Will they work properly as the items inside the scene if I start to edit the views, use zooms and so on?

wysota
25th June 2009, 12:53
You can create a custom item if you need to and draw inside its proper drawing routine. But you can use the painter path item with the first method I suggested.

jano_alex_es
25th June 2009, 14:52
Sorry, I'm not talking clearly:

What I have, right now, it's a Graphics View "promoted to" my own "view class", in order to control all the events. Inside, I have some clasess, some inherits from qGraphicsItemLine, other from QGraphicsItemGroup... it depends what do I need to do with them.

I also have an scene added to myView.cpp. From the view code I control, for example, the zoom with the mouse wheel.

But I'm having troubles when I try to draw the object which inherits from QGraphicsItemGroup, it will have a polygon form but I don't know if the polygon will interact properly with the graphics view and, also, if I create a polygon item on the top the events of the itemgroup could be lost (because the events, like "on click", of the itemPolygon will be called instead). That can be solved... but I don't want to have more items when I just want to paint a polygon.

So, after the explanation my question is: if I paint some forms from qpainter, in my scene and view, will they react properly when I interact and change the views, like the items do? in the documentation seems like it's. somehow, divided, "qpaint object" in one side and "scene, views and items" on the other. And QPainter is connected to the widget, not connected to the view...

But, on the other hand, I just want to have a non-event-oriented item.

wysota
25th June 2009, 22:11
No, they won't. If you use Graphics View, use items only. Unless of course you are really convinced you know what you are doing.

jano_alex_es
29th June 2009, 11:12
QPainterPath::lineTo() and QPainter::drawLines() in general.

I will need to have the lines sorted in the array (drawLines) if I want to have the joins, won't I?

wysota
29th June 2009, 11:14
Yes, the lines have to connect.

jano_alex_es
29th June 2009, 16:11
Does it work with multiple joins? like, for instance:

http://i39.tinypic.com/2503ux2.jpg

If I add the red line just after the black one in the vector, I suppose the join just will be done between those two and nothing will be done if I try to connect with the blue one.

If so, any way to "create a join" between three lines?

thanks!

wysota
29th June 2009, 19:31
You can paint the red line again the other way (so that you paint two red lines instead of one) to have a "sequence" with the blue one.