PDA

View Full Version : Graphics View



parulkalra14
13th February 2014, 09:19
This code is to match a text int in a block and draw a rectangle at a given position. That is working correctly for one variable but i want when two variables are there in a program then two rectangles will draw.
For Example :
int a,b;
then i want two rectangles will appear (one rectangle for variable a and another for variable b) in graphics view
Can someone help me?

if(cursor.block().text().contains("int",Qt::CaseInsensitive))
{
scene.addRect(100,0,90,90,QPen(Qt::black),QBrush(Q t::darkBlue));
ui->graphicsView->setScene(&scene);

}

anda_skoa
13th February 2014, 09:53
If you want one rectangle, you call addRect() onces.
If you want two rectangles, you call addRect() twice. With different coordinates or size if you want them to visually distinguishable.

Cheers,
_

parulkalra14
13th February 2014, 11:23
Sir for one program this solution is fine but not for bulk of programs. I want if one variable then one rectangle will show, if two variables then two rectangles will show , if three variables three rectangles will show and so on.

stampede
13th February 2014, 12:02
I want if one variable then one rectangle will show, if two variables then two rectangles will show , if three variables three rectangles will show and so on.
Then draw your rectangles in a loop...

anda_skoa
13th February 2014, 12:51
Sir for one program this solution is fine but not for bulk of programs. I want if one variable then one rectangle will show, if two variables then two rectangles will show , if three variables three rectangles will show and so on.

You will be surprised to read this, but in order to get three rectangles, addRect() needs to be called three times!

If we assume the laws of induction apply, we can derive that in order to get N rectangles, you'll need to call addRect() N times.

Cheers,
_

parulkalra14
17th February 2014, 07:40
ok..sorry sir for the wrong one..but thanku so much.....