读书人

请问图片里写字的有关问题

发布时间: 2012-01-19 20:57:58 作者: rapoo

请教图片里写字的问题
比如一段代码:

C/C++ code
        QGraphicsScene *sceneImageRef = new QGraphicsScene;        vueRef->setScene(sceneImageRef);        QImage imageRef;        imageRef.load(fileNom2);        QPixmap pixmapRef = QPixmap::fromImage(imageRef.scaled(vueRef->size(), Qt::IgnoreAspectRatio));        sceneImageRef->addPixmap(pixmapRef);


就是在指定的框里显示一张名字为fileNom2的图片(可以zoomin,zoomout),然后我想在显示的这张图片上写字(显示字,比如"Qt, hello!"),怎么实现呢?
用QPainter类的drawText方法吗?
谢谢!

[解决办法]
然后怎么把这个QPixmap绘制到QWidget的QPainter上??
谢谢!

void paintEvent(QPaintEvent *event) {
QPainter painter(this);
painter.drawImage(....); // 在这里绘制你得到的pixmap
}

读书人网 >QT开发

热点推荐