0

Toolbar(SelectionToolBar)是允许的LeftToolbarArea。并且目前是隐藏的。当我将鼠标移到应用程序的左边框时,它会附带定义不透明度的动画。这工作正常。但问题是当我将鼠标移到鼠标上时toolbuttons,所有工具按钮都会隐藏,尽管我可以单击按钮,但它可以工作。只有工具按钮显示(查看/查看)被隐藏。我怀疑“fade_effect”超出了范围。有什么解决办法吗?

bool evenfilter(...)
{
 ... 
  QGraphicsOpacityEffect* fade_effect = new QGraphicsOpacityEffect();
  ui->SelectionToolbar->setGraphicsEffect(fade_effect);
  QPropertyAnimation *animation = new QPropertyAnimation(fade_effect, "opacity");
  animation->setEasingCurve(QEasingCurve::InOutQuad);
  animation->setDuration(3000);
  animation->setStartValue(0.01);
  animation->setEndValue(1.0);
  animation->start(QPropertyAnimation::DeleteWhenStopped);
//animation->start();
  ui->SelectionToolbar->show();
}
4

1 回答 1

1

这应该是一个BUG

这是@KYL3R 提到的一个BUG

演示重现:

#include <QToolBar>
#include <QToolButton>
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>

class ToolBar : public QToolBar
{
    Q_OBJECT
public:
    ToolBar(QWidget *parent = Q_NULLPTR) :
        QToolBar(parent)
    {
        setGraphicsEffect(&mFadeEffect);
        mFadeAnimation.setTargetObject(&mFadeEffect);
        mFadeAnimation.setPropertyName("opacity");
        mFadeAnimation.setStartValue(0.0);
        mFadeAnimation.setEndValue(1);
        mFadeAnimation.setDuration(3000);
        mFadeAnimation.start();
    }
    virtual ~ToolBar() {}

private:
    QGraphicsOpacityEffect  mFadeEffect;
    QPropertyAnimation      mFadeAnimation;
};

auto toolbar = new ToolBar();
toolbar->addAction("action 1");
toolbar->addAction("action 2");
toolbar->addAction("action 3");

addToolBar(Qt::LeftToolBarArea, toolbar);

临时解决方案:

改变

mFadeAnimation.setEndValue(1);

mFadeAnimation.setEndValue(0.99);
于 2018-06-07T07:31:05.820 回答