【问题标题】:How to make combobox item not selectable in qml?如何使组合框项目在 qml 中不可选择?
【发布时间】:2020-01-31 10:12:40
【问题描述】:

如果 itemSwitch1 为“ON”,我想让 itemSwitch2 不可选 我怎样才能拒绝访问 itemSwitch2

function setSelectable(item, state)
{
    item.editable = state
}

StyledComboBox {
   id: itemSwitch1
   Layout.row: 0
   Layout.column: 1
   model: ["ON", "OFF"]
   currentIndex: (root.systemInfo.itemEn) ? 0 : 1
   onUpDownPressed:
   {
       currentIndex = !currentIndex;
   }
   onEditFinished: {
      dashboard.setSelectibale(itemSwitch2, false)
      optionProvider.upDate(currentIndexItem.text)
      itemLabel1.focus = true;
      updateTimer.running = true;
    }
}

【问题讨论】:

  • 我认为你可以使用enabled
  • 我尝试将启用设置为“false”,但该项目仍然可选择!
  • 请分享一个最小的工作示例,以便其他 stack-overflowers 可以尝试复制和帮助
  • 这能回答你的问题吗? ComboBox disable an item at a particular index
  • 不,不是真的!,事实上,如果 itemSwitch1.text 为“ON”,则希望禁用 itemSwitch2 的选择

标签: qt qml


【解决方案1】:

这只是一个例子,但它确实有效:

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 1.4

Window {
    visible: true
    width: 640
    height: 480

    Row {
        spacing: 2
        ComboBox {
            id: one
            width: 200
            model: [ "ON", "OFF" ]

            onCurrentIndexChanged: {
                if (currentIndex === find("ON")) {
                    two.enabled = false
                } else
                {
                    two.enabled = true
                }
            }
        }

        ComboBox {
            id: two
            width: 200
            model: [ "HELLO", "BYE" ]
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-16
    • 2013-12-04
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 2021-06-04
    • 2014-10-09
    相关资源
    最近更新 更多