How to drawline in a QWidget or any onther?
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:
Code:
{
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.
Re: How to drawline in a QWidget or any onther?
You must overload paintEvent() in class which you want to drawline.
Re: How to drawline in a QWidget or any onther?
Quote:
Originally Posted by
yangyunzhao
I just want to drawline when I need. And I want to control the line's positon uncontrolled.
Could you elaborate on that?