Qt-如何设置QLabel图像顶部的文本

Qt-如何设置QLabel图像顶部的文本,qt,mobile,qt4,nokia,Qt,Mobile,Qt4,Nokia,我相信使用了QPainter,但我不知道如何将两者结合起来 QLabel* imageLabel = new QLabel(); QImage image("c://image.png"); imageLabel->setPixmap(QPixmap::fromImage(image)); imageLabel->setAlignment(Qt::AlignCenter); QPainter* painter = new QPainter(); painter->setPen

我相信使用了QPainter,但我不知道如何将两者结合起来

QLabel* imageLabel = new QLabel();
QImage image("c://image.png");
imageLabel->setPixmap(QPixmap::fromImage(image));
imageLabel->setAlignment(Qt::AlignCenter);

QPainter* painter = new QPainter();
painter->setPen(Qt::blue);
painter->setFont(QFont("Arial", 30));
painter->drawText(rect(), Qt::AlignCenter, "Text on Image");

你需要告诉画家在哪里画画:

QImage image("c://image.png");

// tell the painter to draw on the QImage
QPainter* painter = new QPainter(&image); // sorry i forgot the "&"
painter->setPen(Qt::blue);
painter->setFont(QFont("Arial", 30));
// you probably want the to draw the text to the rect of the image
painter->drawText(image.rect(), Qt::AlignCenter, "Text on Image");

QLabel* imageLabel = new QLabel();
imageLabel->setPixmap(QPixmap::fromImage(image));
imageLabel->setAlignment(Qt::AlignCenter);

这不管用。“调用QPainter::QPainter(QImage&)没有匹配函数”候选函数是QPainter::QPainter(QPaintDevice*)。。。构造函数需要一个指针,因此您需要将映像的地址提供给构造函数。在映像上绘制还是覆盖qtextlabel更快?