I want to use Animation which toggled by clicking on specific button. Here is my code:
source:
void MainWindow::menuClicked()
{
//if animation is shown , try to hide it
if (m_menuOpend){
m_animation = new QPropertyAnimation(widgetAnimate, "geometry");
m_animation->setDuration(200);
m_animation->setStartValue(QRect(0, 43, 400, 5*windowsHeight/6));
m_animation->setEndValue(QRect(-300, 43, 400, 5*windowsHeight/6));
m_animation->setEasingCurve(QEasingCurve::Linear);
m_animation->start(QPropertyAnimation::DeleteWhenStopped);
m_menuOpend = false;
}else{
//if widget has not created
if (!widgetAnimate){
widgetAnimate = new QWidget (this);
}
widgetAnimate->show();
m_animation = new QPropertyAnimation(widgetAnimate, "geometry");
m_animation->setDuration(200);
m_animation->setStartValue(QRect(-300, 43, 400, 5*windowsHeight/6));
m_animation->setEndValue(QRect(0, 43, 400, 5*windowsHeight/6));
m_animation->setEasingCurve(QEasingCurve::Linear);
m_animation->start(QPropertyAnimation::DeleteWhenStopped);
m_menuOpend = true;
}
}
header:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QWidget *widgetAnimate;
};
Actually I give an error on
widgetAnimate->show();
because it's skip
if (!widgetAnimate)
condition every time. Any suggestion to avoid creating multiple widget?