2017-01-21 7 views
1

Qtのアニメーションフレームワークを使用しようとしています。私は私が間違ってやっている見当がつかないsetGeometryDp: Unable to set geometry 100x30+0+0 on QWidgetWindow/'QPushButtonClassWindow'. Resulting geometry: 120x30+0+0 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).QPropertyAnimationが機能しない

QPushButton button("Animated Button"); 
button.setGeometry(0, 0, 100, 30); 
button.show(); 

QPropertyAnimation animation(&button, "geometry"); 
animation.setDuration(10000); 
animation.setStartValue(QRect(0, 0, 100, 30)); 
animation.setEndValue(QRect(250, 250, 100, 30)); 

animation.start(); 

:エラー、私はQtのウェブサイトからいくつかのサンプルコードを使用していますが、それは働いていません。

答えて

0

オブジェクトがスコープの外に出る

これは動作します:

QPushButton *button = new QPushButton(); 
button->setGeometry(0, 0, 100, 30); 
button->show(); 

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

animation->start(); 

編集: 私の最終的な解決策

QPushButton *button = new QPushButton(this); 
button->setGeometry(0, 0, 100, 30); 
button->show(); 

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

connect(animation, SIGNAL(finished()), animation, SLOT(deleteLater())); 

animation->start(); 
+2

*これは*、**動作し、それはの完璧な例ですメモリリーク**。ヒープに割り当てているので、インスタンス化している 'button'の親を設定してください。ドキュメントの[このページ](https://doc.qt.io/qt-5/objecttrees.html)を参照してください。 – Mike

+0

助けを借りてくれてありがとう、私はそれを完全に逃した。 – CraftyScoundrel

+1

また、より多くの漏れを防ぐためにアニメーションの '' '' finish() ''信号を '' '' deleteLater() ''スロットに接続してください。 –

関連する問題