我想熟悉qml控件组件的区域设置属性,我知道它用于Qlocale方法,但我找不到任何好的例子
如果要
更改特定控件上使用的区域设置,可以在C++模型上导出字符串属性:
class MyModel : public QObject
{
Q_OBJECT
Q_PROPERTY(QString editLocale MEMBER editLocale_) //more elaborate variants are possible
private:
QString editLocale_;
}
在 main(( 中导出模型:
QQuickView view;
MyModel theModel;
view.rootContext()->setContextProperty("theModel", &theModel);
在 QML 中按如下方式使用它:
CheckBox {
onClicked: {
checked = !checked
if(checked)
theModel.editLocale = "nl_NL"
else
theModel.editLocale = "en_US"
}
SpinBox { //this is derived from the QtQuick.Controls 2.5 Control type you are looking at
locale: Qt.locale(theModel.editLocale)
to: 2000
value: 1000
}
在此示例中,您应该看到在切换复选框时在点和逗号之间切换千位分隔符。
警告:此代码未经过测试,因为我的环境无法识别 locale
属性