To paint on a device, usually a widget, we need to overload the function void QWidget::paintEvent(QPainteEvent *event){}
We also need to construct the object of QPainter in the function of paintEvent like this: QPainter painter(this);
Then we will be able to use QPainter whataver we like.