How can I paint on a widget without overwriting the paintEvent
.
I want to paint on a widget which is inside another one generated by Qt Designer , so i can't overwrite its paintEvent
.
I tried to paint directly like this :
QPainter *painter= new QPainter(ui->drawArea);
painter.drawLine(50,50,50,150);
painter.close();
but Qt tell me that the QPainDevice
is 0 or something like this,
I tried the same example by creating the painter then call the begin()
method with the QPaintDevice
(the widget) but same problem.
Qt version : 4.8.6.
Using custom widgets in Designer is not an issue. In Designer, add your widget as any other QWidget or QPushButton, depending which has the closest inheritance. Then with right click menu select Promote to ...
, add your MyWidget.h
and then promote the widget to MyWidget
with reimplemented paintEvent()
. Read more:
http://doc-snapshots.qt.io/4.8/designer-using-custom-widgets.html#promoting-widgets