qt - QML:按钮在使用 Material Style 的图像上变得透明
问题描述
我希望我的应用程序使用图像作为背景。所以我使用这段代码:
在我的应用程序窗口中:
Image {
id: bkgImage
source: "qrc:/images/bkg.jpg"
anchors.centerIn: parent
}
添加按钮
Button {
id: btnAsistencia
text: qsTr("ASISTENCIA")
font.pixelSize: fhButttonTextSize
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: btnInscripcion.bottom
anchors.topMargin: parent.height*0.1
}
上面的代码是第二个按钮,但我之前添加了一个完全相同的方式。这是结果:
第二个按钮在图像上变得透明。我怎样才能防止这种情况?
解决方案
Material.background
您可以使用附加属性设置按钮的背景颜色:
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0
ApplicationWindow {
id: window
width: 400
height: 440
visible: true
color: "red"
Button {
text: qsTr("ASISTENCIA")
Material.background: "#666"
}
}
默认颜色具有一定的透明度:
推荐阅读
- xml - 我无法从我的 xml 中以 xsl 编码获取子循环中的根节点数据
- git - Sourcetree - 更改分支文件夹分隔符
- python - 如何返回单个单元格值而不是整行。Excel 到 Python Tkinter
- amazon-web-services - 更改实例 ssh 管理员凭据
- java - 编写一个方法来确定一个数字是否能被 11 整除并返回 true 或 false。以及从 11 到 110 生成 100 个随机整数
- python - 如何检查文件是否在指定时间之间创建?
- c - 有没有可以用特定编译器编译的函数?
- jenkins - 通过 Jenkins Shell 检查 TCP 连接
- docker - BC 17 在 Docker 环境中安装
- java - 使用 java 依赖创建 excel 文件时出错