-1

I created the Start Menu by inheriting QMenu. I want to show and hide it using QPropertyAnimation in sliding style

Problem:
Show & hide are working fine when I call them explicitly(on click of start button). But when I click outside of start menu it hides instantly. Please suggest me what could be cause behind this:

My class is StartMenuUiClass which inherited from QMenu
mptrobj_animation is QPropertyAnimation object

void StartMenuUiClass::show()
{
    this->raise();
    disconnect(mptrobj_animation,SIGNAL(finished()),this,SLOT(this_hide()));
    QMenu::show();
    mptrobj_animation->setDuration(500);
    mptrobj_animation->setStartValue(*mptrobj_startPosition);
    mptrobj_animation->setEndValue(*mptrobj_endPosition);
    mptrobj_animation->start();
}

void StartMenuUiClass::hide()
{
    mptrobj_animation->setDuration(450);
    mptrobj_animation->setStartValue(*mptrobj_endPosition);
    mptrobj_animation->setEndValue(*mptrobj_startPosition);
    connect(mptrobj_animation,SIGNAL(finished()),this,SLOT(this_hide()));
    mptrobj_animation->start();
}

void StartMenuUiClass::this_hide()
{
    this->lower();
    emit work_Done();
    QMenu::hide();
}
Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
Jai
  • 1,292
  • 4
  • 21
  • 41
  • it may be related to QMenu signal aboutToHide(), you can connect a slot to it which can perform a check hide or not like so. – Tab Oct 21 '13 at 12:48
  • I would suggest to install connection **before** calling `start()` function in your `StartMenuUiClass::hide()` function. – vahancho Oct 21 '13 at 12:48

1 Answers1

1

I think, if you click outside of your menu widget, it simply hides or closes without involving your StartMenuUiClass::hide() function. You can try to handle QMenu::hideEvent(QHideEvent *event) and/or QWidget::closeEvent(QCloseEvent *event). Something like this:

StartMenuUiClass::closeEvent(QCloseEvent *event) // the same for hideEvent()
{
    this->hide();
    event->accept();
}
vahancho
  • 20,808
  • 3
  • 47
  • 55
  • @Jai, what did you do and what is happening? – vahancho Oct 22 '13 at 13:11
  • I override hideEvent and closeEvent as you said before. But same thing is happening, when i click my start button start menu is showing and hiding properly but when i click outside menu it hide instantly – Jai Oct 23 '13 at 05:26