0

可能重复:
Qt - QPropertyAnimation 中存在错误?

我想为 QWidget maximumWidth 设置动画,以便在带有动画的布局中更改 thd 小部件的大小,但它不起作用。我试图做以下事情:

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

编辑:对于 minimumWidth 属性动画有效,但对于 maximumWidth - 没有。因此,我在他们的错误报告网站上打开了一个错误:here

4

1 回答 1

0

您的问题只是 maximumWidth 不是用于动画的非常好的属性,因为它不会直接转换为 Widget 的实际大小。你更好地使用geometry它会产生更好的效果;例如,像这样,它为 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();
        }
};
于 2010-07-20T21:03:53.850 回答