Incorrect/weird QLocale locale for widgets under Ubuntu/GNOME
-
Qt 6.4.2 as compiled/supplied with Ubuntu 24.04. I run under GNOME desktop/windowing system, with xcb rather than Wayland.
In a
QStyledItemDelegatesubclass I overrideQString NumberItemDelegate::displayText(const QVariant &value, const QLocale &locale) const /*override*/so as to output a numeric column with large integers to display in my default UK locale so as to get the,separator for thousands. But I do not get commas from theconst QLocale &localepassed in. Which is weird, because both my default & system locales do have it:QString NumberItemDelegate::displayText(const QVariant &value, const QLocale &locale) const /*override*/ { bool ok; int val = value.toInt(&ok); if (ok) { //TEMPORARY // Bit odd? My widget locale seems to have OmitGroupSeparator set, preventing 1,000s being shown with their comma QLocale systemLocale = QLocale::system(); QLocale defaultLocale = QLocale(); qDebug() << "locale parameter" << locale.toString(val) << locale.numberOptions() << locale.numberOptions().testFlag(locale parameter "9971334" QFlags(0x1) true qDebug() << "systemLocale" << systemLocale.toString(val) << systemLocale.numberOptions() << systemLocale.numberOptions().testFlag(QLocale::OmitGroupSeparator); qDebug() << "defaultLocale" << defaultLocale.toString(val) << defaultLocale.numberOptions() << defaultLocale.numberOptions().testFlag(QLocale::OmitGroupSeparator); return defaultLocale.toString(val); } return QStyledItemDelegate::displayText(value, locale); }with output:
locale parameter "9971334" QFlags(0x1) true systemLocale "9,971,334" QFlags() false defaultLocale "9,971,334" QFlags() falseYou can see for now I am having to ignore the
localepassed in, but I should be able to respect that.ChatGPT has hallucinations about there being a
QGuiApplication::locale()used for widgets, but that does not exist. I am fed up chasing its suggestions. Contrary to what it says/suggests, if I look at the locale on the widget (QTableWidget) with the delegateQLocale locale = ui->twFlat->locale(); qDebug() << "widget locale" << locale.toString(123456789) << locale.numberOptions() << locale.numberOptions().testFlag(QLocale::OmitGroupSeparator);I get
widget locale "123,456,789" QFlags() false. So it not a widget setting, I only see it indisplayText(). Beginning to wonder whether Qt for a table item at least chooses to pass in a locale withOmitGroupSeparatorset deliberately...?- Can anyone try this on Ubuntu/GNOME or similar to see if they get the same, please?
- Does anyone know where/how the locale being passed in here gets its settings from, such that it and only it has
QLocale::OmitGroupSeparatorset? - If this is from some sort of GNOME/mutter/whatever setting, does anyone know where that is so I can look at/alter it.
-
See qabstractitemview.cpp, line 4015
@Christian-Ehrlicher
OK, https://codebrowser.dev/qt6/qtbase/src/widgets/itemviews/qabstractitemview.cpp.html#3947 (QAbstractItemView::initViewItemOption())option->locale = locale(); option->locale.setNumberOptions(QLocale::OmitGroupSeparator);OK, fair enough! Thanks. I'll mark this as solution for any future readers :)
-
See qabstractitemview.cpp, line 4015
-
See qabstractitemview.cpp, line 4015
@Christian-Ehrlicher
For me https://codebrowser.dev/qt6/qtbase/src/widgets/itemviews/qabstractitemview.cpp.html#4015 is just a comment againstQAbstractItemView::scrollDirtyRegion(). Could you provide the link for whatever to look at, please? -
See qabstractitemview.cpp, line 4015
@Christian-Ehrlicher
OK, https://codebrowser.dev/qt6/qtbase/src/widgets/itemviews/qabstractitemview.cpp.html#3947 (QAbstractItemView::initViewItemOption())option->locale = locale(); option->locale.setNumberOptions(QLocale::OmitGroupSeparator);OK, fair enough! Thanks. I'll mark this as solution for any future readers :)
-
J JonB has marked this topic as solved