Hello everybody,
This is my first experience in QML. My task is to load a random piece (square) of a big image to QML-form on timer signal. The least of application is wriiten in C++, so I decided to realize timer and copying the part of the image in C++-model and display them through QQuickPaintedItem, redefined paint() and calling update() in the slot of the item.
This is how I redefined paint ():
SomeItem::paint( QPainter *painter )
{
painter -> eraseRect( contentsBoundingRect());
painter -> drawImage( QPoint(0,0), image );
}
This is QML-file with registered item:
import QtQuick 2.0
import SomeItem 1.0
Rectangle {
width: 500
height: 500
SomeItem {
width: 100
height: 100
}
}
I see no result. To make check easier, I temporarily put in paint() this code:
SomeItem::paint( QPainter *painter )
{
painter -> eraseRect( contentsBoundingRect());
painter -> fillRect( contentsBoundingRect(), Color );
}
Color is declared as Q_PROPERTY and I change it on timer signal, then slot emits Color_Changed() and calls update(). This time I see the result, but the color doesn’t change. QML-form shows only the first color with which I initialized Color in item constructor.
I have a few questions about it:
What am I doing wrong?
How to declare Q_PROPERTY for QImage correctly in this case?
In standard widgets I use the second thread for random coordinates calculation and copying of the part of bigger QImage to the smaller to avoid the stop of event handling by interface. Is there any use in doing it in QML?
Thank you.
↧