PDA

View Full Version : drawLine not working



papillon
30th December 2011, 00:12
I'd like to draw a simple line into a frame, but nothing is showing. What I'm doing wrong? Thanks

void myClass:buildInterface()
{
QFrame *myFrame;
........
QPainter *p;
p=new QPainter();
p->begin(myFrame);
p->drawLine( QPoint(0,0), QPoint(500,500) );
p->end();
}

stampede
30th December 2011, 05:59
You need to subclass the QFrame and reimplement paintEvent, its the only valid way to paint on widgets:

Painting using a QPainter can only take place in a paintEvent() or a function called by a paintEvent().