Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML QtQuick.Controls 2.2 Combobox doesn't have selectByMouse; What is the alternative?

We are using QtQuick.Controls 2.2 and can't downgrade due to various reasons. When we use Combobox util from QML, it doesn't appear with selectByMouse field which was introduced in 1.4 version.

Our requirement is -- to be able to select the text in the combobox for copying purpose as well as have a dropdown menu.

How to fix this issue; Is there any alternative?

like image 660
iammilind Avatar asked Jan 04 '23 11:01

iammilind


1 Answers

You can just alter the contentItem to be a TextField of with the properties of your choice. This might look like this:

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

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

Note that, if you edit the text, and editText is not an element of your model, it will not be accepted to be the displayText.

This works for QtQuick.Controls 2.2 onwards, as the properties editable and editText need to exist. Then it will automatically copy the edited text back to displayText once it is a valid input.
For earlier versions, this is much harder to achieve.

like image 172
derM Avatar answered May 02 '23 01:05

derM