QPropertyAnimation* animation = new QPropertyAnimation(myButton, "pos"); animation->setDuration(1000); animation->setStartValue(QPoint(0, 0)); animation->setEndValue(QPoint(100, 100)); animation->start();
QGraphicsRectItem* rectItem = new QGraphicsRectItem(QRect(0, 0, 50, 50)); rectItem->setOpacity(0); QPropertyAnimation* animation = new QPropertyAnimation(rectItem, "opacity"); animation->setDuration(1000); animation->setStartValue(0); animation->setEndValue(1); animation->start();This code creates a QGraphicsRectItem and sets its opacity to 0. Then, it creates a QPropertyAnimation object that animates the opacity property of the rectItem from 0 to 1 over a period of 1000 milliseconds. Package library: Qt Core library.