PDA

View Full Version : How to drawline in a QWidget or any onther?



yangyunzhao
28th August 2009, 03:59
I want to drawline in a QWidget or any other suitable controls.

Somebody tolds me can overload paintEvent().

1.If I use QT designer to create UI, I cannot drawline with this codes:


void iLCDEmulator::paintEvent(QPaintEvent *)
{
QPainter paint(ui.displayWidget); //ui.displayWidget is a QWidget.
//If use "QPainter paint(this) " ,it will drawline in my main windows.
paint.setPen(Qt::red);
paint.drawLine(0,0,50,50);
}


2.If overload paintEvent(), this function will be called at the program statrs or "the widget was obscured and has now been uncovered".
I just want to drawline when I need. And I want to control the line's positon uncontrolled.

kwisp
28th August 2009, 07:00
You must overload paintEvent() in class which you want to drawline.

wysota
28th August 2009, 07:19
I just want to drawline when I need. And I want to control the line's positon uncontrolled.

Could you elaborate on that?