Qt World Summit: Register Today!

Animation Framework documentation

  • Hello,

    I am learning Qt for Python from the docs, scattered tutorials and a few, rare, YouTube videos. The experience has been particularily difficult, especially compared to other frameworks (e.g. SwiftUI), due to the scarcity of well-organised learning material. The official documentation especially is often very terse and uses C++ for its examples, which doesn't help.

    I have managed to build a couple of interactive applications, though, from what I've learned and I wish to continue my understanding of the framework.

    A major hurdle for me is the Animation Framework. I've tried to use it to animate very basic stuff — a QGraphicsItem's opacity for example — but up to now nothing has worked. I've read the docs for QPropertyAnimation and Property, and tried to follow some web tutorials which go through the same examples. But I can't find a detailed explanation of the class which could help me design my own animations. For example, I couldn't find an explanation of what the 'geometry' string refers to in the following code, or a list of other string which can be passed in this case:

    animation = QPropertyAnimation(myWidget, "geometry")

    Is the any resource you could recommend for learning about this part of the framework, especially when it comes to animating QGraphicsItem objects?

    Thank you for your patience.

  • Lifetime Qt Champion

    @Strangelove said in Animation Framework documentation:

    I couldn't find an explanation of what the 'geometry' string refers to in the following code

    It refers to the "geometry" property of the QWidget class: https://doc.qt.io/qt-5/qwidget.html#geometry-prop
    QPropertyAnimation animates properties, so you have to provide name of the property you want to animate.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    The Python documentation is generated from the C++ documentation but not all the C++ snippets have been translated yet (work in progress on that front).

    That said, most of the C++ examples and snippets should not be too complicated to translated to Python.

    As for your question about "geometry", it's literally the name of the property you are going to animate.

    QObject based classes can have a number of Q_PROPERTY, these are the ones you can modify using QPropertyAnimation provided that said property is writable.

  • Thank you for your quick replies. I've followed @jsulm's link and was surprised to see a list of properties. I wondered how I could have missed that. Then I went to the equivalent page in the Python docs, where the list is presented as part of the "functions" list, where functions and properties are mixed together. I understood then why it didn't click for me, as this is far from obvious to a beginner IMHO.

    I presume I can now animate properties of QWidget, but I still can't figure out how to do the same with a QGraphicsItem. I really miss a comprehensive introduction to the framework using Python, since all of the existing books I saw use C++ (which is far from trivial to pick up, especially if you're already struggling with a new GUI framework).

    Any ideas on:

    • QGraphicsItem animation using Python?
    • Leaning resources I might have missed?

    Thanks again.

  • Lifetime Qt Champion

    @Strangelove There is https://doc.qt.io/qtforpython/PySide6/QtWidgets/QWidget.html#groups-of-functions-and-properties But it is also not really clean and obvious. You should also check C++ Qt documentation for now, maybe the Python documentation will improve one day :-)

  • @jsulm said in Animation Framework documentation:

    maybe the Python documentation will improve one day :-)

    I certainly hope so. Thanks.

Log in to reply