PDA

View Full Version : How to paint (QPainter) on a label ?



d@nyal
29th May 2010, 18:36
Hi,
I have several labels on my screen(mainwindow.ui) And I need to draw on them(Overlay).
Unfortunately "Qpainter" just draws behind labels.



void MainWindow::paintEvent( QPaintEvent * event )
{
QPainter painter(this);
painter.setPen(QPen(Qt::black, 2));

//ui->pushButton->clearFocus();
//ui->pushButton->setAutoFillBackground(true);
//ui->pushButton->setBackgroundRole();
//ui->pushButton->setForegroundRole();


//painter.setBackgroundMode();

QPainterPath path;
path.moveTo(qrand() % 80, qrand() % 320);
path.cubicTo(200, 80, 320, 80, 480, 320);
painter.setPen(QPen(Qt::black, 8));
painter.drawPath(path);
}

I searched for lots of beheviars belonging "QPainter" and "QLabel".

Can you guide me how can I fix it?


Thanks.

tbscope
29th May 2010, 18:39
Some tips:
You paint on the main window "canvas".
Labels are put on top of the main window.
So, if you want to paint on top of the labels, you need to paint in the labels