小编Pad*_*n42的帖子

将图像从 C++ 更新为 QML

我正在尝试将 QImage 从 c++ 更新为 QML,

我正在使用以下方法: https: //www.huber.xyz/?p =477

我实现了 QQuickPaintedItem - 显示了初始 QImage,但如果我在那里收到信号(FileWatcher),我找不到从 c++ 更新 QImage 的方法。

我的实现如下所示:

质量管理语言:

ImageItem {
 id: liveImageItem
 height: parent.height
 width: parent.width            
 objectName: "liveImageItem"
}
Run Code Online (Sandbox Code Playgroud)

我将图像注册为:

qmlRegisterType<QUIQImageItem>("imageItem", 1, 0, "ImageItem");
Run Code Online (Sandbox Code Playgroud)

图像的实现:

ImageItem::ImageItem(QQuickItem *parent) : QQuickPaintedItem(parent) {
  qDebug() << Q_FUNC_INFO << "initializing new item, parent is: " << parent;

  this->current_image = QImage(":/resources/images/logo.png");
}

void ImageItem::paint(QPainter *painter) {
  qDebug() << Q_FUNC_INFO << "paint requested...";

  QRectF bounding_rect = boundingRect();
  QImage scaled = this->current_image.scaledToHeight(bounding_rect.height());
  QPointF center = …
Run Code Online (Sandbox Code Playgroud)

c++ qt qml

5
推荐指数
1
解决办法
4251
查看次数

标签 统计

c++ ×1

qml ×1

qt ×1