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. QTabelView with Arabic-Indic numerals for the vertical header
Forum Updated to NodeBB v4.3 + New Features

QTabelView with Arabic-Indic numerals for the vertical header

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 1.8k 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.
  • C Offline
    C Offline
    CroCo
    wrote on last edited by
    #1

    I'm working on a project that requires arabic-indic numerals for numbering the vertical header. I've managed to set them manually as follows:

    m_model = new QStandardItemModel(this);
    m_model = new QStandardItemModel(15,3,this);
    m_model->setHorizontalHeaderItem(0, new QStandardItem(QString("الاول")));
    m_model->setHorizontalHeaderItem(1, new QStandardItem(QString("الثاني")));
    m_model->setHorizontalHeaderItem(2, new QStandardItem(QString("الثالث")));
    QStringList vertHeaders;
    vertHeaders << "١" << "٢" << "٣";
    m_model->setVerticalHeaderLabels( vertHeaders );
    ui->tableView->setModel(m_model);
    ui->tableView->setLayoutDirection(Qt::RightToLeft);
    ui->tableView->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
    

    With the following output:

    0_1515304836022_Untitled.png

    How to configure it and use Arabic-Indic as a default numbering system?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      I would go as far as to say this is a Qt Bug.
      The problem is https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qheaderview.cpp.html#2765 is using QVariant::toString instead of QLocale::toString

      You'd need to subclass QHeaderView and reimplement void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const copy paste basically everything, wiggle out of using private stuff and replace opt.text = d->model->headerData(logicalIndex, d->orientation, Qt::DisplayRole).toString(); with:

      const QVaraiant textData = model()->headerData(logicalIndex, orientation(),Qt::DisplayRole);
      switch(textData.type()){
      case QMetaType::Int:
       opt.text = locale().toString(textData.toInt());
      break;
      // other cases for double/float, unsigned int and other signed/unsigned things (short, long long, etc), and dates/times
      default:
       opt.text = textData.toString();
      }
      
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      C 2 Replies Last reply
      4
      • VRoninV VRonin

        I would go as far as to say this is a Qt Bug.
        The problem is https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qheaderview.cpp.html#2765 is using QVariant::toString instead of QLocale::toString

        You'd need to subclass QHeaderView and reimplement void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const copy paste basically everything, wiggle out of using private stuff and replace opt.text = d->model->headerData(logicalIndex, d->orientation, Qt::DisplayRole).toString(); with:

        const QVaraiant textData = model()->headerData(logicalIndex, orientation(),Qt::DisplayRole);
        switch(textData.type()){
        case QMetaType::Int:
         opt.text = locale().toString(textData.toInt());
        break;
        // other cases for double/float, unsigned int and other signed/unsigned things (short, long long, etc), and dates/times
        default:
         opt.text = textData.toString();
        }
        
        
        C Offline
        C Offline
        CroCo
        wrote on last edited by
        #3

        @VRonin Thank you for the answer. Would you please elaborate how can I subclass QHeaderView and how to pass the customized class to TableView. Thank you.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by SGaist
          #4

          Hi,

          QTableView::setVerticalHeader.

          class LocalizedHeaderView : public QHeaderView
          {
          protected:
              void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
              {
                  // The code
                  const QVariant textData = model()->headerData(logicalIndex, orientation(),Qt::DisplayRole);
                  switch (textData.type()) {
                      case QMetaType::Int:
                      opt.text = locale().toString(textData.toInt());
                      break;
                      // other cases for double/float, unsigned int and other signed/unsigned things (short, long long, etc), and dates/times
                  default:
                      opt.text = textData.toString();
                  }
                  // Rest of the code
              }
          };
          

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          C 1 Reply Last reply
          2
          • SGaistS SGaist

            Hi,

            QTableView::setVerticalHeader.

            class LocalizedHeaderView : public QHeaderView
            {
            protected:
                void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
                {
                    // The code
                    const QVariant textData = model()->headerData(logicalIndex, orientation(),Qt::DisplayRole);
                    switch (textData.type()) {
                        case QMetaType::Int:
                        opt.text = locale().toString(textData.toInt());
                        break;
                        // other cases for double/float, unsigned int and other signed/unsigned things (short, long long, etc), and dates/times
                    default:
                        opt.text = textData.toString();
                    }
                    // Rest of the code
                }
            };
            
            C Offline
            C Offline
            CroCo
            wrote on last edited by
            #5

            @SGaist
            I got this error

            error: 'd_func' is a private member of 'QHeaderView'
                    Q_D(const QHeaderView);
            
            1 Reply Last reply
            0
            • VRoninV VRonin

              I would go as far as to say this is a Qt Bug.
              The problem is https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qheaderview.cpp.html#2765 is using QVariant::toString instead of QLocale::toString

              You'd need to subclass QHeaderView and reimplement void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const copy paste basically everything, wiggle out of using private stuff and replace opt.text = d->model->headerData(logicalIndex, d->orientation, Qt::DisplayRole).toString(); with:

              const QVaraiant textData = model()->headerData(logicalIndex, orientation(),Qt::DisplayRole);
              switch(textData.type()){
              case QMetaType::Int:
               opt.text = locale().toString(textData.toInt());
              break;
              // other cases for double/float, unsigned int and other signed/unsigned things (short, long long, etc), and dates/times
              default:
               opt.text = textData.toString();
              }
              
              
              C Offline
              C Offline
              CroCo
              wrote on last edited by
              #6

              @VRonin said in QTabelView with Arabic-Indic numerals for the vertical header:

              wiggle out

              How do I avoid private members?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Just thought of a possibly simpler way: why not subclass the headerData method and fix there the returned value ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                C 1 Reply Last reply
                0
                • SGaistS SGaist

                  Just thought of a possibly simpler way: why not subclass the headerData method and fix there the returned value ?

                  C Offline
                  C Offline
                  CroCo
                  wrote on last edited by
                  #8

                  @SGaist could you please elaborate a bit?

                  mrjjM 1 Reply Last reply
                  0
                  • C CroCo

                    @SGaist could you please elaborate a bit?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @CroCo
                    Hi
                    headerdata is a virtual function in the model
                    http://doc.qt.io/qt-5/qabstractitemmodel.html#headerData
                    It returns the data used in headers for any HedaderView attached.

                    1 Reply Last reply
                    0

                    • Login

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