views:

61

answers:

2

I wanted to animate the QWidget maximumWidth in order to change thd widgets size in a layout with animation, but it does not work. I have tried to do the following:

QPropertyAnimation *animation1 = new QPropertyAnimation(m_textEditor2, "maximumWidth");
animation1->setStartValue(0);
animation1->setEndValue(100);
animation1->start();

EDIT: For minimumWidth property the animation works, but for maximumWidth - no. Thus I have opened a bug on bugreports.qt.nokia.com. Here it is.

A: 

Your problem is just that maximumWidth isn't a very good property to use for animation, since it doesn't directly translate to the Widget's actual size. You better use geometry which gives a better effect; like this for example, it animates a QTextEdit:

class QtTest : public QMainWindow
{
    Q_OBJECT
    public:
        QtTest()
        {
            m_textEdit = new QTextEdit(this);
        };

    protected:
        QTextEdit *m_textEdit;

        virtual void showEvent ( QShowEvent * event )
        {
            QWidget::showEvent(event);

            QPropertyAnimation *animation = new QPropertyAnimation(m_textEdit, "geometry");
            animation->setDuration(10000);
            animation->setStartValue(QRect(0, 0, 100, 30));
            animation->setEndValue(QRect(0, 0, 500, 30));

            animation->start();
        }
};
Gianni
The promblem comes from http://stackoverflow.com/questions/3283587/qwidget-resize-animation question.So if it is not possible with maximumWidth, then how it is possible to solve the problem previous problem?
Narek
Honestly, I've been trying to help you with that, but that other code is just tooooo long. :-) Laziness is a powerful force, young padawan! I'm gonna take a wild guess here and say that resizing animations might not be working because of the Q*Layout guys. Try this: put a Panel/ScrollBox/QWidget in the layout and the widget you want to animate inside it without *any* layouts. Maybe that works.
Gianni
Without layout to animate maximumWidth has no sence for my case. By the way minimumWidth property animates fine! So this should work as well, isn't it?
Narek
A: 

See this link.

Narek