Qt/QML : Send QImage From C++ to QML and Display The QImage On GUI

后端 未结 4 918
执念已碎
执念已碎 2020-12-23 11:34

I created a class Publisher which periodically emits a QImage object.

However I\'m having a tough time drawing the QImage to

4条回答
  •  盖世英雄少女心
    2020-12-23 12:36

    When I've had image-producing C++ classes I've wanted to embed in QML, I've always done it by making the C++ class a subclass of QDeclarativeItem (there'll be a new QtQuick 2.0 equivalent of course), overriding the paint method with the appropriate drawing code, which maybe as simple as

    void MyItem::paint(QPainter* painter,const QStyleOptionGraphicsItem*,QWidget*) {
      painter->drawImage(QPointF(0.0f,0.0f),_image);
    }
    

    if you have a QImage of the right size already... and Job Done. For animation, just ping update() when there's something new to draw.

提交回复
热议问题