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

Tuesday, March 8th 2005, 12:54pm

drawLine method help?

Hi there i'm trying to use the drawLine method from QPainter to draw a line on my my label..but i dont see anything being drawn!

Here is my code fragment!
pmVideo is the QLabel,

void IdentifyMarkersForm::drawPiesSlot()
{
QPainter *painter=new QPainter(pmVideo);
QColor col("yellow");
QString tempString;
painter->setPen(col);
double pWidth=pmVideo->pixmap()->width();
double pHeight=pmVideo->pixmap()->height();
int i=0;
while(tempMarkerList.Marker_ID!=-1){
tempString.setNum(tempMarkerList[i].Marker_ID);
painter->drawText(tempMarkerList[i].x,tempMarkerList[i].y,tempString);
painter->drawPie(tempMarkerList[i].x,tempMarkerList[i].y,30,30,10,5760);
painter->drawLine(23,30,100,100);
i++;
}

}

Thanking you all in advance.
Regards

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

2

Tuesday, March 8th 2005, 1:05pm

RE: drawLine method help?

Quoted

Originally posted by m_i_m
void IdentifyMarkersForm::drawPiesSlot()
{
QPainter *painter=new QPainter(pmVideo);
...
while(tempMarkerList.Marker_ID!=-1){
...
i++;
}
}

Are you sure that tempMarkerList[0].Marker_ID != -1?
Where do you delete that QPainter --- don't you have a memory leak?

Try this:

Source code

1
2
3
4
5
void IdentifyMarkersForm::drawPiesSlot()
{
    QPainter painter(pmVideo);
    ...
}
You should reimplement paintEvent() of that label and do your drawing there or draw everything on a pixmap and assign it to that label --- now, when your window gets under other one, all you have drawn will vanish.

3

Tuesday, March 8th 2005, 1:13pm

Yes Marker_ID does become -1!... i do print out the values in the list and they are there!

And i changed it to use the normal variable QPainter and not a pointer and it still doesnt work!

Thanks

4

Tuesday, March 8th 2005, 1:18pm

Some of my debug text...This just indicates that there are are markers and that they are valid x and y values!
=========================================================
--->drawPies stuff
ID 30 :x 181.901;y 385.718
30 181.901 385.718
--->drawPies stuff
ID 31 :x 192.556;y 99.3184
31 192.556 99.3184
--->drawPies stuff
ID 32 :x 281.581;y 22.1577
32 281.581 22.1577
--->drawPies stuff
ID 33 :x 237.729;y 235.236
33 237.729 235.236
--->drawPies stuff
ID 34 :x 304.082;y 528.425
34 304.082 528.425
--->drawPies stuff
ID 35 :x 534.518;y 171.522
35 534.518 171.522
--->drawPies stuff
ID 36 :x 535.453;y 531.377
36 535.453 531.377
--->drawPies stuff
ID 37 :x 307.723;y 171.528
37 307.723 171.528
--->drawPies stuff
ID 38 :x 232.174;y 459.594
38 232.174 459.594
--->drawPies stuff
ID 39 :x 573.408;y 20.421
39 573.408 20.421
Number of Markers drawn = 10

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

5

Tuesday, March 8th 2005, 1:54pm

How big is that label? Is it shown? When it redraws itself, all what you have drawn will be lost.

Again, you should create a subclass of QWidget and reimplement paintEvent or do your drawing on a pixmap, that you assign to that label later.

Source code

1
2
3
4
5
6
7
8
void IdentifyMarkersForm::drawPiesSlot()
{
   QPixmap pixmap;
   QPainter painter(&pixmap);
   ...
   painter.end();
   pmVideo->setPixmap(pixmap);
 }

6

Tuesday, March 8th 2005, 2:18pm

Well the label is big almost like 768x576. I figured that it would be simpler to draw pies at the respective coordinates on the label than on the pixmap!...

I need to subclass QLabel and put my drawing of the pies code in the paint method, so that it will always get re-drawn when it gets repainted. Whats a quick way to do this?

Thanking you
Regards

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

7

Tuesday, March 8th 2005, 2:39pm

Quoted

Originally posted by m_i_m
I need to subclass QLabel and put my drawing of the pies code in the paint method, so that it will always get re-drawn when it gets repainted. Whats a quick way to do this?

There is no quick way. You have to create a subclass with at least a constructor and paintEvent method.

http://doc.trolltech.com/3.3/tutorial1-09.html
http://doc.trolltech.com/3.3/t9-cannon-h.html
http://doc.trolltech.com/3.3/t9-cannon-cpp.html

8

Tuesday, March 8th 2005, 3:00pm

Thanks, i will look up on that and get back to you guys.

Regards

9

Wednesday, March 9th 2005, 12:11pm

I have had a look at the above links, my question now is!

-I take it that i should create a new class and inherit from the QLabel class?
-Once i've done that i need to include the paintEvent in it...right?
-From the paintEvent, can i set the Pixmap of my new class as well, before drawing on the pixmap?

Thanks
Regards

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

10

Wednesday, March 9th 2005, 1:11pm

Quoted

Originally posted by m_i_m
-I take it that i should create a new class and inherit from the QLabel class?

You can also create a subclass of QWidget itself.

Quoted

-Once i've done that i need to include the paintEvent in it...right?

Yes.

Quoted

From the paintEvent, can i set the Pixmap of my new class as well, before drawing on the pixmap?

Do you mean, that you would like to use QLabel::setPixmap and draw your chart on top of that pixmap?