我正在查找 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
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" }
}
}
}
我uploaded将代码发送到 GitHub。
已更新
您可以根据您的要求使用一些TabViewStyle
属性来加载不同的图像。 IE。下一个代码是使用 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" }
}
关于mobile - 选项卡 QML 中的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33376467/