QTabelView with Arabic-Indic numerals for the vertical header
-
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:

How to configure it and use Arabic-Indic as a default numbering system?
-
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 usingQVariant::toStringinstead ofQLocale::toStringYou'd need to subclass
QHeaderViewand reimplementvoid paintSection(QPainter *painter, const QRect &rect, int logicalIndex) constcopy paste basically everything, wiggle out of using private stuff and replaceopt.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(); } -
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 usingQVariant::toStringinstead ofQLocale::toStringYou'd need to subclass
QHeaderViewand reimplementvoid paintSection(QPainter *painter, const QRect &rect, int logicalIndex) constcopy paste basically everything, wiggle out of using private stuff and replaceopt.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(); } -
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 } }; -
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 } }; -
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 usingQVariant::toStringinstead ofQLocale::toStringYou'd need to subclass
QHeaderViewand reimplementvoid paintSection(QPainter *painter, const QRect &rect, int logicalIndex) constcopy paste basically everything, wiggle out of using private stuff and replaceopt.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(); } -
Just thought of a possibly simpler way: why not subclass the
headerDatamethod and fix there the returned value ? -
Just thought of a possibly simpler way: why not subclass the
headerDatamethod and fix there the returned value ? -
@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.