我想要图标来填充 Button
. 这是代码:
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
Window{
id: root
title: "settings"
flags: Qt.Dialog
minimumHeight: 700
minimumWidth: 700
maximumHeight: 700
maximumWidth: 700
ColumnLayout{
id: columnLayout
anchors.fill: parent
RowLayout{
Button{
iconSource: "images/1x1.png"
checkable: true
checked: true
Layout.minimumWidth: 100
Layout.minimumHeight: 100
}
Button{
iconSource: "images/1x2.png"
checkable: true
checked: false
Layout.minimumWidth: 100
Layout.minimumHeight: 100
}
Button{
iconSource: "images/2x1.png"
checkable: true
checked: false
Layout.minimumWidth: 100
Layout.minimumHeight: 100
}
Button{
iconSource: "images/2x2.png"
checkable: true
checked: false
Layout.minimumWidth: 100
Layout.minimumHeight: 100
}
}
Rectangle{
visible: true
implicitHeight: 600
implicitWidth: 700
color: "red"
}
}
}
按钮大小为100 * 100像素,但图像尺寸要低得多 . 如何使图像像按钮一样大
4 回答
如果你不介意使用私有API,那就是padding属性:
看
ButtonStyle.qml
:这实际上取决于你想要达到的目标 . IMO,这里有三个解决方案:
1)如果您需要将图像作为按钮,只需使用
Image
并填充MouseArea
:2)如果要使用带图像的按钮,请重新定义
style
的label
属性,如下所示:这样,您可以在
Button
中放置任何图像,并且边框的小填充允许您查看按钮被单击/选中的时间 . 请注意,通过使用ButtonStyle
,您将失去平台风格 .3)如果你真的想使用
Button
并让它看起来像是一个Image
遵循米奇提出的智能方法 .如果您想要图像将填充按钮:
或者其他
fillMode
,如你所知我在这里说过同样的问题 . 非常感谢不同的解决方案 . 但@folibis建议的那个最终给了一个平台(在Windows 10中是平的)按钮和我的svg图像 . 但它确实可以很好地工作 . 原因有三:1 . 图像与按钮紧密贴合 . 为了保持图标,我使用了FLAT组合框 . 2.当我们在按钮上寻找简单的标志性图像时,fillmode tile是不合适的 . 我已将其更改为PreserveASpectFit . 3.可检查和检查的属性不适用于普通操作按钮 . 但问题的代码示例肯定有这些 . 请在这里查看我的代码 . 可能有用 . 再次感谢@Folibis