【发布时间】:2016-02-17 15:07:01
【问题描述】:
我试图在 Qml 的帮助下实现与QScrollArea(在小部件世界中)类似的东西。
我决定探测Flickable 加上QQuickPaintedItem 基于项目(在我的例子中命名为抽屉):
Flickable {
...
onContentXChanged(): {
drawer.update()
}
Drawer {
id: drawer
...
}
抽屉的渲染目标设置为FrameBufferObject。它的绘制函数如下所示:
void Drawer::paint(QPainter *painter)
{
// Some function to compute rect which is needed to be redrawn
QRect updateRect = computeUpdateRect();
// How to shift contents of Frame buffer, e.g. to right, and draw only updateRect in this space?
}
想象一下我们如何在 QScrollArea 小部件中滚动,例如向左:视口的所有条目都向右移动,左侧唯一的小矩形被重绘。
我想对Flickable+QQuickPaintedItem 做同样的事情。但是有些东西我看不懂:
如何操作 QQuickPaintedItem 中的帧缓冲区对象?
也许有一些更正确的方法可以在 QML 中实现QScrollArea?
顺便问一下,QQuickPaintedItem默认开启双缓冲了吗?
使用Flickable 实现:
提供有关任务的更多信息:我有一个非常大的“图片”。所以我不能将它全部加载到内存中,但我必须使用视口之类的东西来浏览它。
【问题讨论】:
-
QQuickPaintedItem与QPainter一起使用。就速度而言,这不是最好的主意,所以我建议您使用QQuickItem并直接使用 OpenGL。无论如何,如果您使用QQuickPaintedItem,您可以设置QQuickPaintedItem::setRenderTarget(QQuickPaintedItem::FramebufferObject),因此QPainter 使用GL 绘制引擎绘制到QOpenGLFramebufferObject(来自Qt 文档) -
@folibis 感谢您的回复,您知道是否有一种手动操作此帧缓冲区的方法,或者只能通过 QPainter 接口访问?我在文档中没有找到有关它的信息。
标签: qt qml qt-quick qscrollarea