Author Topic: ComboBox onCurrentIndexChanged run during QML Setup  (Read 2622 times)

I've got a comboBox that references a ListModel "tokenVars", ex: { label: "Project Directory"; variable: "$(projDir)" }. When the user chooses the item in the dropbox, I need to insert the "variable" string into a TextEdit based on cursor position.

The problem I'm having though, is that the onCurrentIndexChanged is run when the plugin ui gets instantiated. This results in my default TextEdit string being editing during instantiation (because add_variable_to_path() appends the the variable string value during setup).

Default TextEdit string:

TextEdit string after plugin qml setup:

Example Code:
AlgComboBox {
id: comboBox_VarSelect_Path
onCurrentIndexChanged: {

function add_variable_to_path() {"Current Index: " + comboBox_VarSelect_Path.currentIndex + " | MODEL DATA: " + tokenVars.get(comboBox_VarSelect_Path.currentIndex).label, + " " + tokenVars.get(comboBox_VarSelect_Path.currentIndex).variable);
    textInput_OutputPath.insert(textInput_OutputPath.cursorPosition, tokenVars.get(comboBox_VarSelect_Path.currentIndex).variable);

How can I instantiate the ui with default values, and prevent the onCurrentIndexChanged() from changing the defaults during setup?

Fingers crossed, I think I'm close to a solution, but I just ran into this error:

[Script] "AlgTextInput.onTextEdited" is not available due to component versioning.

Does this mean painter supports an older version of qt that does not support this handler?

This is a bug from our current version of Qt.
Here is a workaround:

Code: [Select]
import AlgWidgets 2.0
import QtQml 2.2

AlgTextInput {
  id: root
    target: root
    onTextEdited: alg.log.warn("hello world")