我在 linux 上使用 qtcreator 4.4.1 和 qt 5.9.2-1
我正在尝试创建一个带有 stackview 的选项卡栏,以便我可以在不同的选项卡之间切换。但是标签栏中的标签按钮永远不会出现,如果我单击它们应该在的区域,它们也不起作用。
我尝试添加各种彩色矩形,看看是否能以某种方式将其带到表面,但它从未显示出来……而且我还在大多数组件上添加了 visible: true 。我还试图确保所有东西都有宽度和高度。但即便如此,我仍然无法看到它。
这就是它的样子
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Extras 1.4
import QtQuick.Layouts 1.3
import QtQuick.Templates 2.2
ApplicationWindow {
id: root
flags: Qt.FramelessWindowHint
visible: true
width: 382
height: 748
Column {
id: column1
width: parent.width
height: parent.height
visible: true
TabBar {
id: bar
width: parent.width
height: 50
visible: true
TabButton {
visible: true
text: qsTr("Fruit")
width: parent.width
height: parent.height
Rectangle {
anchors.fill: parent
color: "#ff0000"
visible: true
}
}
TabButton {
visible: true
text: qsTr("Vegetables")
width: parent.width
height: parent.height
Rectangle {
anchors.fill: parent
color: "#00ff00"
visible: true
}
}
TabButton {
text: qsTr("Demons")
width: parent.width
height: parent.height
Rectangle {
anchors.fill: parent
color: "#0000ff"
visible: true
}
}
}
StackLayout {
width: parent.width
height: parent.height
visible: true
currentIndex: bar.currentIndex
Item {
id: fruitTab
Rectangle {
anchors.fill: parent
color: "#ff0000"
visible: true
}
}
Item {
id: vegetableTab
Rectangle {
anchors.fill: parent
color: "#00ff00"
visible: true
}
}
Item {
id: demonTab
Rectangle {
anchors.fill: parent
color: "#0000ff"
visible: true
}
}
}
}
}
我还尝试了 qt 文档给出的简单示例:https ://doc.qt.io/qt-5/qml-qtquick-controls2-tabbar.html#details但这也不起作用。
看起来像这样