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:
{
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);
}
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);
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks