December 4, 2010

phedlund phedlund
Lab Rat
8 posts

Itemviews and rtl languages

 

Hi all,

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.

Any ideas?

11 replies

December 4, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

have you something like this [developer.qt.nokia.com]

December 4, 2010

Volker Volker
Ant Farmer
5428 posts

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)

December 5, 2010

phedlund phedlund
Lab Rat
8 posts

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.

December 5, 2010

xsacha xsacha
Lab Rat
517 posts

What should the itemview do in the case that there is both arabic and english items?

 Signature 

- Sacha

December 5, 2010

Tobias Hunger Tobias Hunger
Robot Herder
3386 posts

xsacha: The same as two line edits do, one with english the other with arabic text? If you have a item with both arabic and english text then it should do what a lineedit does with the same text.

How to mix left-to-right and right-to-left languages is well defined in the unicode standard.

December 5, 2010

phedlund phedlund
Lab Rat
8 posts

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.

December 6, 2010

infoctopus infoctopus
Lab Rat
120 posts

looks like a bug

 Signature 

Qt rulez

December 6, 2010

phedlund phedlund
Lab Rat
8 posts

http://bugreports.qt.nokia.com/browse/QTBUG-15908
https://bugs.kde.org/show_bug.cgi?id=175520

December 6, 2010

infoctopus infoctopus
Lab Rat
120 posts

great that the related KDE bug found. (It’s always harder to find such bugs due to less users care of that features)

 Signature 

Qt rulez

December 6, 2010

phedlund phedlund
Lab Rat
8 posts

Well, that bug is assigned to me. It’s just that I have now found the time and incentive to finally try to sort this out.

December 7, 2010

infoctopus infoctopus
Lab Rat
120 posts

phedlund, great!

 Signature 

Qt rulez

 
  ‹‹ Cast custom class to QObject      QToolbar. Caption and "x" button ››

You must log in to post a reply. Not a member yet? Register here!