[Qt-interest] Qt::LayoutDirection and language

Robert Hairgrove evorgriahr at hispeed.ch
Wed May 12 18:05:33 CEST 2010


It's really wonderful that I can change the text layout direction of 
widgets on the fly! But there are times when additional functionality is 
needed.

For example, the user can choose a subset of the names of the days of 
the week from a list view in my scheduling program. The selected names 
go to a second list view. Also, the user can chosse any locale supported 
by Qt for these names from a dialog (which offers the languages in a 
combo box and the associated countries in another list view).

Almost trivial to set up!  So far, so good, but...

There is no interface, however (AFAICT) to query the locale or the 
language to get the reading direction at runtime. Therefore, my code 
looks something like this:

         // this needs to be fixed!
         int lng = m_locale.language();

         switch(lng)
         {
             case QLocale::Hebrew:
             case QLocale::Arabic:
                 lsvDOW->setLayoutDirection(Qt::RightToLeft);
                 lsvDOWSelected->setLayoutDirection(Qt::RightToLeft);
                 break;
             default:
                 lsvDOW->setLayoutDirection(Qt::LeftToRight);
                 lsvDOWSelected->setLayoutDirection(Qt::LeftToRight);
                 break;
         }

Is there a better way? Surely, there must be (might be) other languages 
with RTL reading direction?



More information about the Qt-interest-old mailing list