我想加载一些图像到QML中的Image对象。我想在循环中一个接一个地做,因为它应该假装看起来像动画。即时通讯和QML新的,所以任何人都可以帮助我如何开始或事端'? :)如何将一堆图像加载到QML中的图像中?
0
A
回答
0
如果使用QtQuick 2然后AnimatedSprite是做到这一点的最好办法:http://qt-project.org/doc/qt-5.0/qtquick/qtquick-effects-sprites.html
否则,您可以使用定时器或NumberAnimation触发改变图像源,但有可能是不可预测的延误图像首次加载(缓存应在第一次循环后解决)。如果你只有几张图片,你可以有三张图片并循环观看。
1
最简单的解决方案,即在QML 1.x和2.0的作品,是使用Repeater
和Timer
:
import QtQuick 2.0
Rectangle {
id: base;
width: 800;
height: 600;
property variant images : [
"image1.jpg",
"image2.jpg",
"image3.jpg",
"image4.jpg",
"image5.jpg"
];
property int currentImage : 0;
Repeater {
id: repeaterImg;
model: images;
delegate: Image {
source: modelData;
asynchronous: true;
visible: (model.index === currentImage);
}
}
Timer {
id: timerAnimImg:
interval: 500; // here is the delay between 2 images in msecs
running: false; // stopped by default, use start() or running=true to launch
repeat: true;
onTriggered: {
if (currentImage < images.length -1) {
currentImage++; // show next image
}
else {
currentImage = 0; // go back to the first image at the end
}
}
}
}
应该这样做,如果你不想动画重新启动时到达最后一张图像,只需在计时器的onTriggered
中将currentImage = 0;
替换为stop();
即可。
此外,您应该可能需要调整一下Repeater
中的Image
代表,以使其具有您想要的外观(尺寸,填充模式,位置等)。
相关问题
- 1. 如何将图像加载到c#中的图像控件?
- 2. 如何在wpf中将图像加载到图像控件?
- 3. 无法在QML图像中加载图像源
- 4. 将图片库中的图像加载到图像源
- 5. 通用图像加载器 - 如何将第二个图像加载到ImageView中?
- 6. 如何从图库中加载图像视图中的图像?
- 7. 如何在运行时生成的QML中加载图像(jpg)
- 8. 如何在Visual Studio中使用C将图像加载到PictureBox中的图像#
- 9. 如何将SD卡中的图像加载到图像切换器中?
- 10. 如何将图像加载到一个div中,哪个图像从数据库加载到另一个div
- 11. 如何从文件加载图像,然后将图像加载到位图?
- 12. 将图像从解析图像加载到图像视图
- 13. 将图像加载到WinRT中的图像UI项目
- 14. 如何从URL中QML加载图像没有QT C++
- 15. 如何在OpenCv C++中将图像添加到图像中
- 16. 如何将图像(Blob)加载到Hbase
- 17. 加载图像到jQuery中
- 18. 将图像加载到另一个线程并在QML中取得进展
- 19. 如何将图像从url数组加载到图像数组?
- 20. 如何将URL中的图像加载到UITableViewCell的UIImageView中?
- 21. 将图像加载到Gridview中
- 22. 无法将图像加载到NSImageView中
- 23. 将图像加载到数组中Java
- 24. 解析 - 将图像加载到GridView中
- 25. 将图像从PHAsset加载到Imageview中
- 26. 将图像加载到Div中
- 27. 将图像加载到listview api中
- 28. 将图像数据加载到Angularjs中
- 29. 将图像加载到控件中
- 30. 将图像对象加载到pygame中