温馨提示:本文翻译自stackoverflow.com,查看原文请点击:qt - How to make combobox item not selectable in qml?

qt - 如何在QML中使组合框项目不可选?

发布于 2020-03-29 21:32:27

如果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;
    }
}

查看更多

提问者
Y. Hacene
被浏览
44
Tarod 2020-02-02 08:16

这只是一个示例,但它可以正常工作:

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" ]
        }
    }
}

发布
问题

分享
好友

手机
浏览

扫码手机浏览