gpt4 book ai didi

Qt - 如何在 QLabel 图像上设置文本

转载 作者:行者123 更新时间:2023-12-04 18:35:29 24 4
gpt4 key购买 nike

我相信使用了 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);

关于Qt - 如何在 QLabel 图像上设置文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4270229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com