简体   繁体   English

如何在QDateTimeEdit中使用Qt :: SystemLocaleShortDate?

[英]How to use Qt::SystemLocaleShortDate in QDateTimeEdit?

In QDateTimeEdit it is possible to set format by string with the setDisplayFormat(const QString &format) , but i see no function which receive Qt::DateFormat enumeration instead of string. 在QDateTimeEdit中,可以使用setDisplayFormat(const QString &format)通过字符串设置格式,但是我看不到任何函数可以接收Qt::DateFormat枚举而不是字符串。

My goal is to have format of QDateEdit depending on user locale. 我的目标是根据用户区域设置QDateEdit的格式。 Maybe it is possible to fetch string format which is used for Qt::SystemLocaleShortDate in fromString and toString but i can't find it. 也许有可能在fromStringtoString获取用于Qt :: SystemLocaleShortDate的字符串格式,但是我找不到它。

You can use this code to set display format. 您可以使用此代码设置显示格式。

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QDateTimeEdit w;
    QLocale currentLocale = QLocale::system();
    w.setDisplayFormat( currentLocale.dateFormat( QLocale::ShortFormat ) + " " + currentLocale.timeFormat( QLocale::ShortFormat ) );
    w.setDateTime( QDateTime::currentDateTime() );
    w.show();
    a.exec();
}

It look like this in Mac 在Mac中看起来像这样 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM