代码之家  ›  专栏  ›  技术社区  ›  Narek

为什么不可能对Qwidget的“maximumWidth”参数设置动画?[副本]

  •  0
  • Narek  · 技术社区  · 15 年前

    可能重复:
    Qt - There is a bug in QPropertyAnimation?

    我想设置QWidget最大宽度的动画,以便在布局中通过动画更改THD小部件的大小,但它不起作用。我已经尝试了以下操作:

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

    编辑:对于MinimumWidth属性,动画可以工作,但对于MaximumWidth-否,因此我在他们的bugReport站点上打开了一个bug: here .

    1 回复  |  直到 8 年前
        1
  •  0
  •   Gianni    15 年前

    您的问题是,MaximumWidth并不是一个很好的动画属性,因为它不能直接转换为小部件的实际大小。你最好用 geometry 这会产生更好的效果;例如,它将 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();
            }
    };