QML:contentItem不显示任何图像
我正在使用QML:contentItem不显示任何图像,qml,qt5,Qml,Qt5,我正在使用QML设计一个小型用户界面 我遇到的问题是,如果某个特定条件发生或未发生,我需要选择一个图像,但什么也没有发生,因为我在下面的contentItem中可能有错误,我设置了一个简单的if循环,它完全复制了我遇到的问题: main.qml // operations .... Row { anchors.fill: parent anchors.leftMargin: 20 anchors.topMargin: 20 Button { id
QML
设计一个小型用户界面
我遇到的问题是,如果某个特定条件发生或未发生,我需要选择一个图像,但什么也没有发生,因为我在下面的contentItem
中可能有错误,我设置了一个简单的if
循环,它完全复制了我遇到的问题:
main.qml
// operations ....
Row {
anchors.fill: parent
anchors.leftMargin: 20
anchors.topMargin: 20
Button {
id: button
width: 90
height: 270
contentItem: Item {
Image {
source: root.selected === 0 ?
source: "qrc:/images/btn-Modes-on.png" :
source: "qrc:/images/btn-modes-normal.png"
}
}
// operations ....
}
我认为问题在于我在哪里为图像设置if
循环。我可以确认图像的路径是正确的,并且经过了仔细检查。
我还根据文档使用了图像的正确符号,我使用的属性是source:“图像路径”
。
但是经过检查,我仍然没有返回
感谢您为解决此问题指明了正确的方向。您的代码中有一个输入错误。图像源应如下所示:
source: root.selected === 0 ?
"qrc:/images/btn-Modes-on.png" :
"qrc:/images/btn-modes-normal.png"
我不知道你说的“如果循环”是什么意思。但是看起来你的
源代码中有一个输入错误。对于条件语句的每一部分,不应该有源代码:
。它应该是这样的:source:root.selected==0?“qrc:/images/btn Modes on.png”:“qrc:/images/btn Modes normal.png”
:)感谢您的关注!真管用!如果你写下答案,我可以接受:)。谢谢你过来看问题!