January 11, 2011

Thomas Penin Thomas Penin
Lab Rat
5 posts

[Solved] Qt layout direction and window title bar

 

Hi all,

I am using Qt 4.2.2 under Windows and facing a localization issue.

The application I am developing can be translated into several languages, including Arabic, which is RTL. I am able to properly invert the entire application layout (using QApplication::setLayoutDirection(Qt::LayoutDirection direction)) but not the title bar (buttons are always on the right).

Having made the first tests on an English OS, I thought that the title bar was still left-to-right because it was the system’s responsibility to handle this part. However, I discovered that the application, when deployed in an Arabic OS, still has the left-to-right title bar direction, contrary to all other applications that were installed.

After having googled for hours I still have not found anything to explain why the title bar still has this wrong orientation. I am wondering if Qt has anything to do with this situation, if it is a known issue or if I shall proceed another way.

Any hint?

8 replies

January 11, 2011

Gerolf Gerolf
Robot Herder
3287 posts

The Title bar on windows is done by the OS, so I think, if you are running on an Arabic windows, it should be correct.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

January 11, 2011

Thomas Penin Thomas Penin
Lab Rat
5 posts

Well, unfortunately it isn’t… I also thinks it is the OS responsibility to handle the title bar, although I have no clue about the reason why my application behaves differently than the others.

Thanks for the reply anyway. I am wondering if someone targeting Arabic OSes already met this issue…

January 11, 2011

ivan.todorovich ivan.todorov..
Lab Rat
96 posts

In Microsoft Windows, you have to set the WS_EX_RIGHT extended window style flag. Extended Window Styles [msdn.microsoft.com]).aspx

Unfortunately, Qt doesn’t provide methods to do so (or at least I’m not aware of them). You have to use the Windows API.

// Edit: Now it should work.

I think you have to do something like this:
(WARNING: Hasn’t been tested)

  1. #ifdef Q_OS_WIN32
  2.     #include "winuser.h"
  3. #endif
  4.  
  5. MainWindow::MainWindow(QWidget *parent) :
  6.     QMainWindow(parent),
  7.     ui(new Ui::MainWindow)
  8. {
  9.     ui->setupUi(this);
  10.  
  11.     #ifdef Q_OS_WIN32
  12.         HWND hWnd = this->winId();
  13.         long extendedStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
  14.         // SetWindowLong(hWnd, GWL_EXSTYLE, extendedStyle | WS_EX_RIGHT); --- oops, didn't work. Edit:
  15.         SetWindowLong(hWnd, GWL_EXSTYLE, extendedStyle | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT);
  16.     #endif
  17.  
  18. }

 Signature 

o_o Sorry for my rusted english.

January 11, 2011

peppe peppe
Ant Farmer
1029 posts

Feel free to submit a bug report for this.

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

January 11, 2011

Andre Andre
Robot Herder
6417 posts

Indeed. It feels like a bug in Qt. If you have Qt in LTR, I’d expect it to set LTR as a hint for the window manager too!

Thanks ivan, that is valuable information.

January 11, 2011

Thomas Penin Thomas Penin
Lab Rat
5 posts

Thanks for your replies.

I did try ivan’s suggestion but it seems to only put the window title to the right, without positioning the buttons to the left. Another flag did perfectly the trick for the entire title bar (WS_EX_LAYOUTRTL) but mirrored the entire application, making any string unreadable and messing with Qt::RightToLeft layout direction (which does more than just mirroring).

I have filled a bug report (QTBUG-16581 [bugreports.qt.nokia.com]) and hope that it will help.

[EDIT: added link to bug report, Volker]

January 11, 2011

ivan.todorovich ivan.todorov..
Lab Rat
96 posts

Thomas Penin wrote:
Thanks for your replies.

I did try ivan’s suggestion but it seems to only put the window title to the right, without positioning the buttons to the left. Another flag did perfectly the trick for the entire title bar (WS_EX_LAYOUTRTL) but mirrored the entire application, making any string unreadable and messing with Qt::RightToLeft layout direction (which does more than just mirroring).

I have filled a bug report (QTBUG-16581 [bugreports.qt.nokia.com]) and hope that it will help.

[EDIT: added link to bug report, Volker]


Ok I did a little research. You have to set both the WS_EX_LAYOUTRTL and WS_EX_NOINHERITLAYOUT flags. This should mirror only the window control, and let its content intact. (Theoreticaly)
Source [microsoft.com]

 Signature 

o_o Sorry for my rusted english.

January 11, 2011

Thomas Penin Thomas Penin
Lab Rat
5 posts

Thanks a lot, ivan. It works!

 
  ‹‹ Could it be possible to have two different connections to handle two different databases?      QImage - Retrieve data from an 8 bit bitmap image ››

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