-1

我通过继承创建了开始菜单QMenu。我想以QPropertyAnimation滑动方式显示和隐藏它

问题:
当我明确调用它们时(单击开始按钮),显示和隐藏工作正常。但是当我在开始菜单之外单击时,它会立即隐藏。请建议我这可能是什么原因:

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();
}
4

1 回答 1

1

我认为,如果您在菜单小部件之外单击,它只会隐藏或关闭而不涉及您的StartMenuUiClass::hide()功能。您可以尝试处理QMenu::hideEvent(QHideEvent *event)和/或QWidget::closeEvent(QCloseEvent *event). 像这样的东西:

StartMenuUiClass::closeEvent(QCloseEvent *event) // the same for hideEvent()
{
    this->hide();
    event->accept();
}
于 2013-10-21T13:05:26.613 回答