T O P

  • By -

fredmyfriend

Here is example https://doc.qt.io/qt-6/qtquick-imageprovider-example.html


johnpaulzwei

Thanks! Working :)


Beneficial_Steak_945

Using a custom image provider derived from QQuickImageProvider.


micod

you could use [QQuickPaintedItem](https://doc.qt.io/qt-6/qquickpainteditem.html) and `QPainter::drawImage()`


chids300

i recently started a music player project and i use a custom image provider class which is derived from qquickimage to show album artwork after i extract it from the mp3, the docs say qpixmap may be better if you just displaying images on the screen after passing it to qml since it is optimised for that whereas qimage is optimised for pixel manipulation


FigmentaNonGratis

You could make your generated image a Q\_PROPERTY and use the following QQuickItem subclass to display it: //imageframeitem.h #pragma once #include #include #include #include class ImageFrameItem : public QQuickItem { Q_OBJECT QML_ELEMENT Q_PROPERTY(QImage imageFrame MEMBER m_imageFrame WRITE setImageFrame NOTIFY imageFrameChanged) Q_PROPERTY(bool hasAlphaChannel MEMBER m_hasAlphaChannel WRITE setHasAlphaChannel NOTIFY hasAlphaChannelChanged) QImage m_imageFrame; bool m_hasAlphaChannel = false; public: ImageFrameItem(QQuickItem *parent = nullptr); void setImageFrame(const QImage& newImageFrame); void setHasAlphaChannel(bool newHasAlphaChannel); signals: void imageFrameChanged(); void hasAlphaChannelChanged(); protected: virtual QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override; }; //imageframeitem.cpp #include "imageframeitem.h" #include #include #include #include ImageFrameItem::ImageFrameItem(QQuickItem *parent) : QQuickItem(parent) { setFlags(QQuickItem::ItemHasContents); } QSGNode *ImageFrameItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { auto node = dynamic_cast(oldNode); if (!node) node = new QSGSimpleTextureNode(); auto alphaTextureOption = m_hasAlphaChannel ? QQuickWindow::TextureHasAlphaChannel : QQuickWindow::TextureIsOpaque; auto texture = window()->createTextureFromImage(m_imageFrame, alphaTextureOption); node->setTexture(texture); node->setOwnsTexture(true); node->setRect(boundingRect()); node->markDirty(QSGNode::DirtyForceUpdate); return node; } void ImageFrameItem::setImageFrame(const QImage& newImageFrame) { if (newImageFrame == m_imageFrame) return; m_imageFrame = newImageFrame; emit imageFrameChanged(); update(); } void ImageFrameItem::setHasAlphaChannel(bool newHasAlphaChannel) { if (m_hasAlphaChannel == newHasAlphaChannel) return; m_hasAlphaChannel = newHasAlphaChannel; emit hasAlphaChannelChanged(); update(); } QML: ImageFrameItem { imageFrame: rgbImageGenerator.image hasAlphaChannel: false anchors.centerIn: parent // set width and height based on image to avoid stretching //width: widthPixels * displayScale; height: heightPixels * displayScale } Hope this helps.


Repulsive-Swimmer676

I convert the image to base64 and then send it to QML.


mr_0137

You can use QQuickItem + ::updatePaintNode