QML QtQuick.Controls 2.2 Combobox does not have selectByMouse; Which alternative?

We use QtQuick.Controls 2.2 and cannot downgrade for various reasons. When we use Comboboxutil from QML, it does not appear with the field selectByMousethat was introduced in version 1.4.

Our requirement is to be able to select text in the combo box for copying, and also have a drop-down menu.

How to fix this problem; Is there an alternative?

+4
source share
2 answers

You can simply change contentItemboth TextFieldwith the properties of your choice. It might look like this:

ComboBox {
    id: control
    model: ['Hallo', 'Hello', 'Sallut', 'Godan Dagin']
    editable: true

    contentItem: TextField {
        text: control.editText
        selectByMouse: true
    }
}

, , editText , displayText.

QtQuick.Controls 2.2 , editable editText . displayText, .
.

+5

Qt 5.9/Quick Controls 2.2, ComboBox TextField, , ComboBox editible. TextField selectByMouse, , ComboBox, QML. javascript, . Component.onCompleted.

:

ComboBox {
    editable: true

    model: ListModel {
        id: model
        ListElement { text: "Banana" }
        ListElement { text: "Apple" }
        ListElement { text: "Coconut" }
    }

    Component.onCompleted: {
        contentItem.selectByMouse = true
    }
}
+3

Source: https://habr.com/ru/post/1685745/


All Articles