I'm trying to realize something similiar to QScrollArea
(in widgets world) with the help of Qml.
I decided to probe Flickable
plus QQuickPaintedItem
based item (named Drawer in my case):
Flickable {
...
onContentXChanged(): {
drawer.update()
}
Drawer {
id: drawer
...
}
Drawer's render target is set to FrameBufferObject
. Its paint function looks like this:
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?
}
Imagine how we do scrolling in QScrollArea
widget, e.g. to left: all entry of viewport is shifted to right and the only small rect in left is redrawn.
I want to do the same with Flickable
+QQuickPaintedItem
. But I can't understand some things:
How can I manipulate Frame Buffer object inside QQuickPaintedItem
?
Maybe there is some more right way to implement QScrollArea
in QML?
By the way, is double buffering enabled by default in QQuickPaintedItem
?
For implementing with Flickable
:
To provide more info about task: I have a very big "picture". So I cannot load it whole into memory, but I have to navigate through it with something like viewport.
A scroll area or a flickable are used when you want to encapsulate a larger content in a smaller area and navigate around it. And in your case that is... not the case. You are not practically using a scroll area as your image is never larger than the scroll area size, you just want to fake it, which is actually quite easy:
And on the QML side:
This is just a quick basic example, there is a lot of room to polish and improve. Also note that if the source rect is different size than the target rect, you can easily achieve zooming in or out. You can hook it to a flickable to get the "kinetic scrolling" instead of the mouse area.