Home > C++, English, KDE, Qt > how to animate almost each layout in qt-4.6

how to animate almost each layout in qt-4.6

I use QGraphicsLinearLayout for example.

First create a new QGraphicsLayout and pass a single QGraphicsWidget in the constructor and create a new QPropertyAnimation:

ProxyLayout::ProxyLayout(QGraphicsWidget *widget, QGraphicsLayoutItem *parent)
: QGraphicsLayout(parent), m_widget(widget)
{

m_animation = new QPropertyAnimation(m_widget, “geometry”);
m_animation->setDuration(300);

}

“ProxyLayout::count() const” returns just 1.
“QGraphicsLayoutItem *ProxyLayout::itemAt(int i) const” returns our widget.
“void ProxyLayout::removeAt(int index)” does nothing.

Now lets implement our animation:

void ProxyLayout::setGeometry(const QRectF &rect)
{

if (m_animation->state() == QPropertyAnimation::Running) {
m_animation->stop();
}

m_animation->setStartValue(m_widget->geometry());
m_animation->setEndValue(rect);
m_animation->start();

QGraphicsLayout::setGeometry(rect);

}

and the sizeHint:

QSizeF ProxyLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{

return m_widget->effectiveSizeHint(which, constraint);

}

Now you can add your widget to the QGraphicsLinearLayout:

QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical, this);
MyWidget *widget = new MyWidget();
ProxyLayout *pLayout = new ProxyLayout(myWidget);
layout->insertItem(index, pLayout);

enjoy your animated layout :)

Kategorien:C++, English, KDE, Qt
  1. Es gibt noch keine Kommentare.
  1. Keine Trackbacks bisher.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Log Out / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Log Out / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Log Out / Ändern )

Verbinde mit %s

Follow

Get every new post delivered to your Inbox.