我如何禁用 QPushbutton 上的突出显示?

How i can disable highlight on a QPushbutton?

Qt 5.11 Linux

我如何禁用图标平面 QPushButton 上的按钮突出显示: 它看起来像:

代码:

m_settingsPushButtton=new QPushButton();
m_settingsPushButtton->setCheckable(true);
m_settingsPushButtton->setChecked(false);
m_settingsPushButtton->setFlat(true);
m_settingsPushButtton->setIcon(QIcon(":/images/settings2"));

起初我认为它可能是默认设置:

m_settingsPushButtton->setDefault(false);
m_settingsPushButtton->setAutoDefault(false);

但事实并非如此。问题依旧 我认为那是因为这个按钮具有焦点 我设置:

m_settingsPushButtton->setFocusPolicy(Qt::NoFocus);

但这又无济于事了。 好的,我可能需要设置按钮 Transapent..

QPalette Theme = m_themePushButtton->palette();
Theme.setColor(QPalette::Button, QColor(Qt::transparent));
m_themePushButtton->setPalette(pal);

没有结果。如何禁用此突出显示。谢谢。

您应该使用样式表将按钮边框设置为 0:

m_themePushButtton->setStyleSheet("border: 0px;");

可能会有帮助