I worked for a long time with QGraphicsItem
and it has transform()
function. Now I wont to do same thing with QQuickItem
but unfortunately it misses transform()
. So my question - how can I get transform matrix for QQuickItem
?
相关问题
- QML: Cannot read property 'xxx' of undefin
- QML: Cannot read property 'xxx' of undefin
- QTextEdit.find() doesn't work in Python
- QT Layouts, how to make widgets in horizontal layo
- QT GUI freezes even though Im running in separate
相关文章
- ubuntu20.4中c#通过c++库调用python脚本
- Qt槽函数自动执行多遍
- Is there a non-java, cross platform way to launch
- How to get a settings storage path in a cross-plat
- Why doesn't valgrind detect a memory leak in m
- QTreeView remove decoration/expand button for all
- qt界面拥挤
- how do I correctly return values from pyqt to Java
The QSGTransformNode class implements transformations in the scene graph. In
updatePaintNode
function, argumentupdatePaintNodeData
provides a pointer to theQSGTransformNode
associated with thisQQuickItem
.Actually the
QQuickItem
provides thetransform()
method, however it returns the list of all transformations assigned to given item. It is because multiple transformations can be assigned to a singleItem
. The return type ofQQuickItem::transform
isQQmlListProperty<QQuickTransform>
— it is a wrapper to QMLlist<Transform>
type (see documentation for Item). It can be iterated over, yieldingQQuickTransform *
elements.QQuickTransform
is a base class for a transformation that provides a virtual methodapplyTo
taking aQMatrix4x4 *
argument and applying the transformation upon it.The QML allows instantiating several
QQuickTransform
subclasses (for translation, rotation and scale) and user is allowed to defined custom transformations (eg. for skew).To obtain a single transformation matrix you need, you have to start with identity matrix and sequentially apply all the transformations of given
QQuickItem
.Note that the function returns a tranformation matrix as
QMatrix4x4
— it is more than oldQTransform
that was based on 3x3 transformation matrix, so it cannot be converted without loss. If you want, you may useQMatrix4x4::toAffine
to get theQMatrix
(3x3) and use it to createQTransform
object. However, if yourQQuickItem
transformations contain non-affinic elements, they will be lost.Edit
There's one more thing to note: the method I posted works only for transformations defined by assigning to
transform
property. It does not check forscale
androtation
properties. If you use them, you should check their values with appropriateQQuickItem
methods and adjust returned matrix to include these two additional tranformations.Here's a correct solution, based on the code provided by Michael earlier, but fixed to work actually, so you don't have to spend 20 minutes figuring out how to use QQmlListProperty
In my use case I use this to get the model matrix for my object, then multiply together with view and projection matrixes to calculate the model-view-projection matrix.