我可以通过这样做在我的 Qlabel 上画一条线:
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);
这有效。我得到一个带有蓝线的红色标签。
但现在我想在 1.jpg 上画一条线,如下所示:
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);
不幸的是现在我只得到我的 1.jpg 但上面没有蓝线。
有人能解释一下吗? 我在Win10 / QT5.6.1 上工作