首页 > 解决方案 > 带有图标的按钮边框

问题描述

在构造函数中,我设置了表单和按钮的样式:

{
    ui->setupUi(this);
    this->setStyleSheet("QWidget {background: rgb(49, 54, 59); color: rgb(220, 221, 218); selection-color: lightyellow; selection-background-color: darkcyan;}"
                        "QPushButton::hover {color: darkcyan; border: 2px solid grey; border-radius: 3px};");
}

接下来,在icon按钮的属性(参数)中,我添加了一个via 资源,我也使用参数 -icon设置了图标大小,我也设置了-参数。iconSize20x20flatTrue

这就是我将光标悬停在按钮上时得到的结果:

在此处输入图像描述

当图片设置为 时,按钮本身的大小是使用布局和 is 形成size的。32x2620x20

请告诉我如何在按钮的和gap之间删除它?pictureborder

我尝试静态设置按钮大小,大约22x22然后一切都或多或少很好,但我不想诉诸这种激进的解决方案。谢谢。

标签: c++qt

解决方案


参考Qt的盒子模型,边框和图标之间的间隙就是padding

在样式表中,您可以将填充设置为 0,如下所示padding: 0px;


推荐阅读