is there any way to insert QPixmap object in html?

后端 未结 4 1068
后悔当初
后悔当初 2021-01-05 22:54

Simple situation: I have an object, which has a QPixmap member. Object first created (pixmap is null now), then pixmap readed from data base and inserted in obj

4条回答
  •  长发绾君心
    2021-01-05 23:01

    If you only want to display a QPixmap in a QLabel, you should use QLabel::setPixmap. You can construct the pixmap in memory by using QPixmap::loadFromData.

    If you want to display a memory pixmap in HTML, e.g. in a QWebView, you can use

        QByteArray byteArray;
        QBuffer buffer(&byteArray);
        pixmap.save(&buffer, "PNG");
        QString url = QString("";
    

    (untested)

    QLabel::setText does not work with HTML but with rich-text. I do not know if the data: protocol is supported by the Qt rich-text implementation.

    Another way to insert a pixmap into a QWebView would be to use a subclass of QNetworkAccessManager and reimplement its createRequest() function to check for URLs with your own protocol ("myprot:") and insert the pixmap data there. But this looks like overkill.

提交回复
热议问题