【问题标题】:How to hide a TabButton inside TabBar in QML如何在 QML 中的 TabBar 内隐藏 TabButton
【发布时间】:2019-07-30 16:44:35
【问题描述】:

我想在 TabBar 中隐藏一个 TabButton。

Visible 属性为按钮保留空间。如果隐藏/可见,我尝试将宽度设置为 0/implicitWidth,但它破坏了布局。

import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Window 2.12

ApplicationWindow {
    visible: true
    width: 640
    height: 480

    header:   TabBar {
        width: parent.width
        TabButton {
            text: qsTr("Home")
        }
        TabButton {
            id: middle
            visible: false
            text: qsTr("Discover")
        }
        TabButton {
            text: qsTr("Activity")
        }
    }

    Button{
        text: "click"
        onClicked: {
            middle.visible = !middle.visible
        }
    }
}

剩下的两个标签应该覆盖所有空间。

【问题讨论】:

    标签: qt qml


    【解决方案1】:

    有人删除了他的答案,所以我重新发布。

    TabButton {
        id: middle
        text: qsTr("Discover")
        width: visible ? undefined : 0
    }
    

    这适用于带有 Qt 5.13 的 Ubuntu。

    取消设置按钮的父级也可以parent: visible ? bar : null

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多