PDA

View Full Version : Realtion between Qmaindow class and Qpainter class



shubham ahir
7th February 2016, 10:11
Are they interdependent
And how to create a qpainter class object to be used in qmaindow class functions like paintevent()

anda_skoa
7th February 2016, 10:38
Are they interdependent

Yes.
One obviously uses the other though.



And how to create a qpainter class object to be used in qmaindow class functions like paintevent()

It is not very comon to override QMainWindow::paintEvent(), maybe you want a custom widget as the main window's centralWidget?

Cheers,
_

Metavoid
8th February 2016, 09:03
Hi
as a fast and "dirty" way to paint
something in main, you can paint on image and show using a QLabel

int w=200;
int h=200;
QPixmap pix(w,h);
QPainter paint(&pix);
paint.setBrush(Qt::white);
paint.drawRect(0,0,w,h);
paint.setBrush(QBrush(QColor(255,34,255,255)));
paint.drawRect(0,0,w/2,h/3);
ui->label->setPixmap(pix);