QTooltip 不需要的行为。来自按钮的图标在工具提示中作为背景部分可见

QTooltip unwanted behaviour. Icon from button is partly visible as background in the tooltip

所以,我认为这张照片不言自明。工具提示应具有黑色文本颜色和浅灰色背景。好吧,如果你仔细看,背景是浅灰色的。但是文本是白色的,最重要的是,显示了启用按钮的图标。这不应该!其他默认按钮,没有图标,工具提示正确显示。 我试图用不透明度(不同的值)和 rgba(211、211、211、0/255)来解决这个问题,但没有任何效果。 这是一个众所周知的问题吗?我的系统是 Windows 10 64 位,我使用 Qt Creator 4.12.2(社区)和 Qt 5.12.9 MinGW 64 位编译器。

#include "mainwindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    MainWindow w;
    w.setStyleSheet("QToolTip { background-color: lightgrey; "
                    "color: black; "
                    "border: none } "
                    "QWidget { color: lightblue; "
                    "background-color: #404040 }");
    w.show();
    return a.exec();
}

该按钮的样式表如下所示:

ui -> CmdSave -> setStyleSheet(" :disabled { color: white; "
                                   "border-image: url(:/miscRsc/misc_icons/filesave_128x128_disabled) 3 10 3 10; "
                                   "border-top: 3px transparent; "
                                   "border-bottom: 3px transparent; "
                                   "border-right: 10px transparent; "
                                   "border-left: 10px transparent } "
                                   ":enabled { color: white; "
                                   "border-image: url(:/miscRsc/misc_icons/filesave_128x128) 3 10 3 10; "
                                   "border-top: 3px transparent; "
                                   "border-bottom: 3px transparent; "
                                   "border-right: 10px transparent; "
                                   "border-left: 10px transparent } "
                                   " :pressed { color: white; "
                                   "border-image: url(:/miscRsc/misc_icons/filesave_128x128_pressed.png) 2 9 2 9; border-top: 2px transparent; "
                                   "border-bottom: 2px transparent; "
                                   "border-right: 9px transparent; "
                                   "border-left: 9px transparent }");

现在我们离问题和解决方案越来越近了。 通过在设置应用程序样式后设置按钮样式,工具提示继承了按钮的样式 - 特别是,它继承了按钮边框图像,这就是为什么您会在工具提示中看到按钮的边框图像。 您可以通过使用后代选择器设置按钮的样式来避免这种情况(我稍微简化了您的样式):

QPushButton:disabled { border-image: url(:/folder.png) 3 10 3 10; border: 3px transparent } 
QPushButton:enabled  { border-image: url(:/folder.png) 3 10 3 10; border: 3px transparent } 
QPushButton:pressed  { border-image: url(:/folder.png) 3 10 3 10; border: 2px transparent }