Thank you very much Santosh Reddy. Your code was very helpful in understanding QAnimationProperty. After understanding your code, I implemented it, but a bit different in approach.
Instead of adding event filter in menu_widget(child widget), I did it in Parent widget. And everything worked fine.
The transition is sharp and final thing now I'm looking for is some smooth transition. And if I give more value in setDuration(), it's affecting in hiding, but not in showing the widget. However for the setDuration(), even after the specified duration, the transition is sharp, whereas smooth would be more eye-pleasing.
I tried using mAnimation->setEasingCurve(QEasingCurve::InOutElastic) and other QEasingCurve properties, but couldn't achieve the smoothness in transition.

But again, thank you for your kind help.

My Code (Implemented similarly based on your's in the previous post):
Qt Code:
  1. // This is mainWidget, where in I'll show the menu
  2. #include "cmainwidget.h"
  3.  
  4. CMainWidget::CMainWidget(QWidget *parent)
  5. : QWidget(parent)
  6. {
  7. this->setMouseTracking(true);
  8. this->setFixedSize(650, 400);
  9. menuWidget = new CMenuWidget(this);
  10. menuWidget->hide();
  11. mAnimation = new QPropertyAnimation(menuWidget, "geometry");
  12. mAnimation->setDuration(250); // Increasing this isn't helping in smooth transition, instead it's affecting hide when the mouse is > 80 in "else if" in mouseMoveEvent
  13. mAnimation->setEasingCurve(QEasingCurve::InOutElastic);
  14. }
  15.  
  16. CMainWidget::~CMainWidget()
  17. {
  18. delete mAnimation;
  19. delete menuWidget;
  20. }
  21.  
  22. void CMainWidget::mouseMoveEvent(QMouseEvent *mmEvent)
  23. {
  24. if(mmEvent->pos().x() <= 80)
  25. {
  26. qDebug("Mouse X-Position - %d", mmEvent->pos().x());
  27. mAnimation->setStartValue(QRect(0, 40, 0, 40));
  28. mAnimation->setEndValue(QRect(0, 40, menuWidget->sizeHint().width(), 40));
  29. disconnect(mAnimation, SIGNAL(finished()), this, SLOT(hideMenuWid()));
  30. mAnimation->start();
  31. menuWidget->show();
  32. }
  33. else if(mmEvent->pos().x() > 80)
  34. {
  35. qDebug("Mouse X-Position - %d", mmEvent->pos().x());
  36. mAnimation->setEndValue(QRect(0, 40, 0, 40));
  37. mAnimation->setStartValue(QRect(0, 40, menuWidget->sizeHint().width(), 40));
  38. connect(mAnimation, SIGNAL(finished()), this, SLOT(hideMenuWid()));
  39. mAnimation->start();
  40. }
  41. }
  42.  
  43. void CMainWidget::hideMenuWid()
  44. {
  45. menuWidget->hide();
  46. }
To copy to clipboard, switch view to plain text mode