0
votes

Is there a way to use different QtQuick widgets in a ListView based on a QVariant's data type?

If my QVariant is a boolean type, the widget would be a Checkbox. If it is an integer, the widget would be a SpinBox. If it is a QString, the widget would be a TextBox.

...etc...

I would like to load/save my application settings with QSettings.

For example:

QSettings settings("userSettings.ini", QSettings::IniFormat);
setAutoUpdate(settings.value("AutoUpdate").toBool());
setAutoUpdateFrequency(settings.value("AutoUpdateFrequency").toInt());
setLastFilePath(settings.value("LastFilePath").toString());

As can be inferred by the conversions, my autoUpdate type is a boolean, my autoUpdateFrequency is an integer, and my lastFilePath is a QString. I was hoping to populate a list within a Settings/Preferences dialog box without having to hard-code and manually position each of the values on the form.

One suggestion by a coworker was that Javascript could determine the QVariant type at creation time and create the new widget, hook up all the necessary properties to the model, and so forth. I'm not sure if that would work, or whether that's the right approach for this situation.

1

1 Answers

0
votes
Item {
    width: parent.width; height: parent.height

    Loader {
       id: myLoader
       source: parent.width<200 ? "ConditionMet.qml" : "ConditionNotMet.qml"
       width: 200
       height: 100
    }

}


This is a sample code you can use to load different modules based on condition .You can use the same to fit your case .
Basically use loader with conditional source .