Qt - How to set text on top of QLabel Image

前端 未结 1 719
悲&欢浪女
悲&欢浪女 2021-01-14 06:08

I believe QPainter is used, but I can\'t figure out how to combine the two.

QLabel* imageLabel = new QLabel();
QImage image(\"c://image.png\");
imageLabel-         


        
相关标签:
1条回答
  • 2021-01-14 07:03

    You need to tell the painter where to draw:

    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);
    
    0 讨论(0)
提交回复
热议问题