Reputation: 11
I can draw a Line on my Qlabel by doing this:
QPixmap *myPixmap;
myPixmap = new QPixmap();
myPixmap->fill(Qt::red);
QPainter painter(myPixmap);
painter.setPen(Qt::blue);
painter.drawLine(1, 1, 50, 50);
ui.label->setPixmap(*myPixmap);
That works. I get a red label with a blue line.
But now i want do draw that line over a 1.jpg like this:
QPixmap *myPixmap;
myPixmap = new QPixmap(ui.label->size());
myPixmap->load("c:\\temp\\1.jpg");
QPainter painter(myPixmap);
painter.setPen(Qt::blue);
painter.drawLine(1, 1, 50, 50);
ui.label->setPixmap(*myPixmap);
Unfortunately now i only get my 1.jpg but no blue line over it.
Can anybody explain this? I work on Win10 / QT5.6.1
Edit to clarify my mistake.
Thanks to the comments of @musicamante and @A.R.M i figured out that the blue line was there but just out of sight because it was to large for the Mainwindow. Unfortunately my original 1.jpg was unicolored so i did not notice that.
I added a frame to my 1.jpg so i can now show the problem i had with 2 screenshots:
Upvotes: 0
Views: 54