【问题标题】:Why it is not possible to animate the "maximumWidth" parameter of the QWidget? [duplicate]为什么不能为 QWidget 的“maximumWidth”参数设置动画? [复制]
【发布时间】:2010-07-20 19:30:46
【问题描述】:

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

我想为 QWidget maximumWidth 设置动画,以便在带有动画的布局中更改小部件的大小,但它不起作用。我已尝试执行以下操作:

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

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

【问题讨论】:

    标签: c++ qt animation qwidget


    【解决方案1】:

    您的问题只是 maximumWidth 不是用于动画的非常好的属性,因为它不会直接转换为 Widget 的实际大小。你最好使用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();
            }
    };
    

    【讨论】:

    • 问题来自stackoverflow.com/questions/3283587/qwidget-resize-animation问题。那么如果maximumWidth是不可能的,那怎么可能解决之前的问题呢?
    • 老实说,我一直在努力帮助你解决这个问题,但是其他代码太长了。 :-) 懒惰是一种强大的力量,年轻的学徒!我要在这里大胆猜测一下,因为 QLayout 的人,调整动画大小可能无法正常工作。试试这个:在布局中放置一个 Panel/ScrollBox/QWidget,并在其中放置您想要动画的小部件,而无需 *any 布局。也许这行得通。
    • 如果没有布局动画最大宽度对我的情况没有意义。顺便说一下 minimumWidth 属性动画很好!所以这也应该有效,不是吗?
    猜你喜欢
    • 2013-01-31
    • 1970-01-01
    • 2013-09-03
    • 1970-01-01
    • 2012-01-29
    • 2019-02-13
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多