Warm tip: This article is reproduced from stackoverflow.com, please click
QT qml

How to make combobox item not selectable in qml?

发布于 2020-03-29 20:59:10

I want to put itemSwitch2 not selectable if itemSwitch1 is "ON" How can I desibale access to the 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;
    }
}
Questioner
Y. Hacene
Viewed
69
Tarod 2020-02-02 08:16

This is just an example, but it is working:

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