Itemviews and rtl languages
I have a problem with displaying rtl languages (mainly Arabic) in a QTableView. No matter what I do the text in a cell is always displayed left aligned. When going into edit mode the QLineEdit displays the text right aligned as expected.
I use a subclassed item delegate. In it I use QPainter::drawText. In the documentation it says that using the version of drawText that takes QRect as a parameter should handle rtl automatically, but it doesn’t.
Pasting Arabic text into any of the demo applications that use item views (e.g. the address book and frozen column samples) show the same in my opinion incorrect behavior.
There is a Qt::TextAlignmentRole in enum Qt::ItemDataRole [doc.qt.nokia.com]. You can use this to store the alignment in your model or item (depending on wether you use the item views or item widgets)
Yes, sure I can specify an alignment. But my impression of the Qt documentation is that these things should be handled automatically. The linedit certainly knows without me telling it. Why doesn’t the table itself? Or the QPainter::drawText()? Run the Qt address book demo and start adding some entries. Do you not expect Arabic to be right aligned when later browsing the entries? Or edit a cell in the frozen column demo with some Hebrew. When you hit enter shouldn’t the cell also display the text right aligned like the editor did?
From http://doc.qt.nokia.com/4.7/internationalization.html (my emphasis):
QPainter::drawText(int x, int y, const QString &str) will always draw the string with its left edge at the position specified with the x, y parameters. This will usually give you left aligned strings. Arabic and Hebrew application strings are usually right aligned, so for these languages use the version of drawText() that takes a QRect since this will align in accordance with the language.
Tobias: Are you saying there is a bug here or is there something that can be done in the code to improve things?
To further underline the inconsistency I have a save as html and print function for my table view also. These both use a QTextDocument with a QTextTable and here the alignment works as expected, i.e. Arabic is rtl in the table cells without me having to do anything special in code.