当在RoundButton中显示svg图像时,我最终得到了固定的宽度(灰色)边框(svg不会填充按钮)。
我使用的图标是圆形的; svg大小设置为匹配该图像。 我尝试过:
添加background: undefined
:删除灰色边框(但不固定图标大小),因此我们看到的是灰色背景。
修改按钮的大小:边框似乎总是相同的宽度,因此看起来分配了固定的边距
将图标更改为正方形:效果相同,顶部,底部,侧面的边框似乎具有固定大小。根据按钮的大小,正方形将包含在按钮内,或“伸出”。
RoundButton {
height: 45
width: height
anchors.top: parent.top
anchors.right: parent.right
icon.source: "qrc:/images/controls/roundInfo.svg"
icon.height: height
icon.width: width
}
如何消除图标周围的空白?
提供简化的svg文件进行测试:
<?xml version="1.0" encoding="UTF-8"?>
<svg width="10.6mm" height="10.6mm" version="1.1" viewBox="0 0 10.6 10.6" xmlns="http://www.w3.org/2000/svg">
<path transform="scale(.265)" d="m20 0c-7.4-3.71e-7 -13.9 4.05-17.3 10.1h34.7c-3.46-6-9.92-10.1-17.3-10.1zm-17.4 10.1c-1.69 2.93-2.67 6.32-2.67 9.95-3.32e-6 11 8.96 20 20 20l-17.4-30zm17.4 30c11 0 20-8.96 20-20 1e-6 -3.62-0.983-7.01-2.67-9.95l-17.4 30z" fill-rule="evenodd" style="paint-order:normal"/>
</svg>
答案 0 :(得分:3)
IconLabel
是contentItem
中的RoundButton
。 contentItem
将由指定的padding
属性填充。默认情况下,此值为12,这会使IconLabel
在每个站点上变小12个像素(因此每个方向总共24个像素)。
请注意,这仅在图标的宽度和高度设置为按钮的大小时才有效,否则图像将再次位于按钮的中心
RoundButton {
height: 45
width: width
icon.source: "qrc:/image.svg"
icon.height: height
icon.width: width
padding: 0 //the trick
}
您可以通过查看安装Qt时获得的QML文件(甚至不是源变量)来查找:<path to>/Qt/5.12.3/gcc_64/qml/QtQuick/Controls.2/RoundButton.qml