Mobile 选项卡QML中的图标
我查看了QML的文档,但没有找到:Mobile 选项卡QML中的图标,mobile,tabs,qml,tabview,Mobile,Tabs,Qml,Tabview,我查看了QML的文档,但没有找到: 有没有办法将图像插入QML中TabView的Tab中 是否可以滚动选项卡 @folibis是正确的,但在他的允许下,我想给您展示一个示例,因为可能很难理解如何在QML选项卡中设置图像 import QtQuick 2.2 import QtQuick.Window 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 Window { id: window wi
- 有没有办法将图像插入QML中
的TabView
中李>Tab
- 是否可以滚动
选项卡
- @folibis是正确的,但在他的允许下,我想给您展示一个示例,因为可能很难理解如何在QML选项卡中设置图像
import QtQuick 2.2
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
Window {
id: window
width: 640
height: 480
visible: true
title: qsTr("Example")
TabView {
anchors.fill: parent
Tab { title: "One" ; Item {}}
Tab { title: "Two" ; Item {}}
Tab { title: "Three" ; Item {}}
Tab { title: "Four" ; Item {}}
style: tabViewStyle
}
Component {
id: tabViewStyle
TabViewStyle {
tabsMovable: true
tab: Item {
implicitWidth: 97
implicitHeight: 28
Image {
id: image
anchors.centerIn: parent
source: styleData.selected ? "images/tab_selected.png" : "images/tab.png"
}
Text {
id: text
text: styleData.selected ? "" : styleData.title
anchors.horizontalCenter: parent.horizontalCenter
}
}
frame: Rectangle { color: "steelblue" }
}
}
}
我将代码转换为GitHub
已更新
根据您的要求,您可以使用一些TabViewStyle
属性来加载不同的图像。也就是说,下一个代码使用int-styleData.index
加载不同的源。代码也在GitHub中
TabViewStyle {
tabsMovable: true
tab: Item {
function loadImage(index) {
return "images/tab"+index+".png";
}
implicitWidth: 97
implicitHeight: 28
Image {
id: image
anchors.centerIn: parent
source: loadImage(styleData.index)
}
Text {
id: text
text: styleData.selected ? "" : styleData.title
anchors.horizontalCenter: parent.horizontalCenter
}
}
frame: Rectangle { color: "steelblue" }
}
我如何执行类似以下操作:text:styleData.selected?{image:source=loadImage(styleData.title+“Active.png”)}:{image:source=loadImage(styleData.title)}
我想在这种情况下,您需要将source设置为source:styleData.selected?“images/tab_selected.png”:“images/tab.png”
并且文本始终与选项卡文本一起:text:styleData.title
您不需要该函数,是吗?