Как сделать элемент в выпадающем списке недоступным для выбора в qml? - PullRequest
1 голос
/ 31 января 2020

Я хочу, чтобы itemSwitch2 был недоступен для выбора, если itemSwitch1 установлен в положение «ON». Как отключить доступ к 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;
    }
}

1 Ответ

0 голосов
/ 02 февраля 2020

Это только пример, но он работает:

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" ]
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...