[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?



  • 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.



  • 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...



  • In Microsoft Windows, you have to set the WS_EX_RIGHT extended window style flag. "Extended Window Styles":http://msdn.microsoft.com/en-us/library/ff700543(v=vs.85).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)

    @
    #ifdef Q_OS_WIN32
    #include "winuser.h"
    #endif

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    #ifdef Q_OS_WIN32
        HWND hWnd = this->winId();
        long extendedStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
        // SetWindowLong(hWnd, GWL_EXSTYLE, extendedStyle | WS_EX_RIGHT); --- oops, didn't work. Edit:
        SetWindowLong(hWnd, GWL_EXSTYLE, extendedStyle | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT);
    #endif
    

    }

    @



  • Feel free to submit a bug report for this.



  • 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.



  • 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":http://bugreports.qt.nokia.com/browse/QTBUG-16581) and hope that it will help.

    [EDIT: added link to bug report, Volker]



  • [quote author="Thomas Penin" date="1294764675"]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":http://bugreports.qt.nokia.com/browse/QTBUG-16581) and hope that it will help.

    [EDIT: added link to bug report, Volker][/quote]
    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":http://www.microsoft.com/middleeast/msdn/mirror.aspx



  • Thanks a lot, ivan. It works!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.