Add the ability to read/write boolean properties in the qt_viewer example

This commit is contained in:
Simon Hausmann 2024-10-10 13:08:36 +00:00
parent f01ac8fc39
commit e9924f0f76

View file

@ -97,6 +97,10 @@ int main(int argc, char **argv)
ui.prop_value->setText(QString::number(*val->to_number()));
break;
case slint::interpreter::Value::Type::Bool:
ui.prop_value->setText(*val->to_number() ? "true" : "false");
break;
default:
ui.prop_value->clear();
break;
@ -124,6 +128,20 @@ int main(int argc, char **argv)
}
break;
}
case slint::interpreter::Value::Type::Bool: {
if (ui.prop_value->text() == "true") {
val = true;
} else if (ui.prop_value->text() == "false") {
val = false;
} else {
QMessageBox::critical(
&main, QApplication::translate("qt_viewer", "Set Property Error"),
QApplication::translate("qt_viewer", "Invalid conversion to boolean, must be true or false"),
QMessageBox::StandardButton::Ok);
return;
}
break;
}
default:
QMessageBox::critical(
&main, QApplication::translate("qt_viewer", "Set Property Error"),