Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Incorrect/weird QLocale locale for widgets under Ubuntu/GNOME

Incorrect/weird QLocale locale for widgets under Ubuntu/GNOME

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 91 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote last edited by
    #1

    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 QStyledItemDelegate subclass I override QString 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 the const QLocale &locale passed 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() false
    

    You can see for now I am having to ignore the locale passed 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 delegate

        QLocale 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 in displayText(). Beginning to wonder whether Qt for a table item at least chooses to pass in a locale with OmitGroupSeparator set 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::OmitGroupSeparator set?
    • If this is from some sort of GNOME/mutter/whatever setting, does anyone know where that is so I can look at/alter it.
    1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      See qabstractitemview.cpp, line 4015

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote last edited by JonB
      #4

      @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 :)

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote last edited by
        #2

        See qabstractitemview.cpp, line 4015

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        JonBJ 2 Replies Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          See qabstractitemview.cpp, line 4015

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote last edited by
          #3

          @Christian-Ehrlicher
          For me https://codebrowser.dev/qt6/qtbase/src/widgets/itemviews/qabstractitemview.cpp.html#4015 is just a comment against QAbstractItemView::scrollDirtyRegion(). Could you provide the link for whatever to look at, please?

          1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            See qabstractitemview.cpp, line 4015

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote last edited by JonB
            #4

            @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 :)

            1 Reply Last reply
            0
            • JonBJ JonB has marked this topic as solved

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved