【问题标题】:QML Editable Tab title within TabView on double-click双击时 TabView 中的 QML 可编辑选项卡标题
【发布时间】:2020-03-02 23:14:46
【问题描述】:

是否可以实现双击后在TabView中编辑选项卡标题的可能性?我的意思完全如下。

我查看了 Tab、TabView 和 TabBar 文档,但没有找到任何有助于实现上述功能的内容。

【问题讨论】:

    标签: qt tabs qml tabbar tabview


    【解决方案1】:

    您可以在 QML 的任何其他项目中嵌入任何内容。通过使用states,可以让 TabButton 在不同的状态下运行(呵呵),在本例中为"editing" 状态,其中某些部分仅在该状态下显示,而其他部分则被隐藏。

    您应该将以下内容放在一些 qml 中

    import QtQuick 2.0
    import QtQuick.Controls 2.3
    
    TabButton {
        id: btn
    
        onDoubleClicked: state = "editing"
    
        TextField {
            id: editor
            anchors.fill: parent
            text: btn.text
            visible: false
            onAccepted: {
                btn.text = text
                btn.state = ""
            }
        }
    
        states: [
            State {
                name: "editing"
                PropertyChanges {
                    target: editor
                    focus: true
                    visible: true
                }
                PropertyChanges {
                    target: btn
                    explicit: true
                    restoreEntryValues: false
                    text: "" //so the text won't show up during editing
                }
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-27
      • 2019-08-12
      • 1970-01-01
      • 2012-01-15
      相关资源
      最近更新 更多