开发者

Why it is not possible to animate the "maximumWidth" parameter of the QWidget? [duplicate]

开发者 https://www.devze.com 2023-01-08 07:25 出处:网络
This question already has answers 开发者_JAVA技巧here: Closed 11 years ago. Possible Duplicate: Qt - There is a bug in QPropertyAnimation?
This question already has answers 开发者_JAVA技巧here: Closed 11 years ago.

Possible Duplicate:

Qt - There is a bug in QPropertyAnimation?

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 their bugreport site: here.


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();
        }
};
0

精彩评论

暂无评论...
验证码 换一张
取 消