小编Bas*_*not的帖子

如何向 QPushButton 添加悬停过渡?

我尝试QPushButton使用样式表进行自定义。当我们将鼠标悬停在按钮上时,我想自定义按钮的颜色。它有效,但我想设置一个过渡持续时间。但在 Qt 中,此选项不可用。

这是我的自定义按钮:

#include "bouton.h"

Bouton::Bouton(QString title, QWidget *parent) : QPushButton()
{
  setGeometry(50,50,120,40);
  setText(title);
  setMinimumHeight(30);
  setParent(parent);
  setStyleSheet(" QPushButton {"
              "border-radius: 5px; "
              "border: 1.5px solid rgb(91,231,255); "
              "background-color: white; }"
              "QPushButton:pressed {"
              "border: 1.4px solid rgb(73,186,205); }"
              "QPushButton:hover {"
              "font-size: 16px;"
              "transition: 0.9s; }");
}
Run Code Online (Sandbox Code Playgroud)

“过渡 0.9 秒”的论点不起作用。

这是CSS 中的一个例子。

还有其他方法可以做到这一点吗?

c++ qt transition hover qwidget

3
推荐指数
1
解决办法
6835
查看次数

标签 统计

c++ ×1

hover ×1

qt ×1

qwidget ×1

transition ×1