You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, July 29th 2010, 3:47pm

How to draw many items in scene

Hi,
I draw line on defined scene but when I want to draw item should I write this line
for example to draw two line should I write that :


Source code

1
2
3
4
5
QGraphicsLineItem *line1 = new QGraphicsLineItem(0,&scene)
p, li { white-space: pre-wrap;  line1->setLine(0.0,0.0,10.0,10.0);
QGraphicsLineItem *line2 = new QGraphicsLineItem(0,&scene);
line2->setLine(0.0,0.0,10.0,10.0);
How can avoid this? I need to draw may lines without repeate that line

2

Thursday, July 29th 2010, 10:14pm

Could you use a loop?
For example:

for (int i = 0; i < theNumberOfLinesYouWant; i++)
{
QGraphicsLineItem *line = new QGraphicsLineItem(0, &scene);
line->setLine(0.0, 0.0, 10.0, 10.0);
}

3

Friday, July 30th 2010, 11:20am

I know loop but I mean is there any another way for line definition of line for example in QPainter

QPainter line;
line.drawline(.......); // first line
line.drawLine (......); // second line
.
.
.

4

Friday, July 30th 2010, 2:21pm

Oh, okay.
QGraphicsScene has a functions addLine(), so you could write

scene->addLine(0.0, 0.0, 10.0, 10.0);
http://doc.trolltech.com/4.5/qgraphicsscene.html#addLine


Hope this helps!

5

Friday, July 30th 2010, 2:49pm

that is good , but i will find problem when I want to change the item coordinate because the line will be drawn on the scene coordinate
i need in the QGraphicsItem terms

6

Friday, July 30th 2010, 7:45pm

I got it , Thanks for every one here