Hi all,

I'd like to animate (show and hide) a widget when a toggle button is pressed.
I wrote this code:
Qt Code:
  1. MainWindow::MainWindow
  2. {
  3. [...]
  4. //ui->widget->hide();//[1]
  5. //ui->button->setChecked(false);//[2]
  6. startgeometry = QRect(0,0,0,0);
  7. connect(ui->button,SIGNAL(toggled(bool)),this,SLOT(togglePyShell(bool)));
  8. }
  9.  
  10. void MainWindow::togglePyShell(bool show)
  11. {
  12. QRect formerGeometry = QRect(ui->widget->geometry());
  13. if(startgeometry==QRect(0,0,0,0)){
  14. startgeometry = formerGeometry;
  15. }
  16. if(show){
  17. //ui->widget->show();//[3]
  18. QPropertyAnimation *showAnimation = new QPropertyAnimation(ui->widget, "geometry");
  19. showAnimation->setDuration(100);
  20. showAnimation->setEasingCurve(QEasingCurve::Linear);
  21. showAnimation->setStartValue(formerGeometry);
  22. showAnimation->setEndValue(startgeometry);
  23. showAnimation->start(QPropertyAnimation::DeleteWhenStopped);
  24. }else{
  25. QPropertyAnimation *hideAnimation = new QPropertyAnimation(ui->widget, "geometry");
  26. hideAnimation->setDuration(100);
  27. hideAnimation->setEasingCurve(QEasingCurve::Linear);
  28. hideAnimation->setStartValue(formerGeometry);
  29. QPoint endTopLeftCorner = QPoint(ui->widget->pos() + QPoint(0, ui->widget->height()));
  30. QRect finalGeometry = QRect(endTopLeftCorner, QSize(ui->widget->width(), 0));
  31. hideAnimation->setEndValue(finalGeometry);
  32. hideAnimation->start(QPropertyAnimation::DeleteWhenStopped);
  33. //ui->widget->hide();//[4]
  34. }
  35. }
To copy to clipboard, switch view to plain text mode 

It works if the widget is visible after costructor (and button pressed), but I'd like to start with the widget invisible (and button not checked).

I don't know how to hide the widget.
If i try to uncomment from [1] up to [4] or subset of them I have strange behaviour, because (i guess) I can't save original widget's size into startgeometry.

Any help is appreciated,
Thanks in advance.