Important: Please read the Qt Code of Conduct -

Reversing the layout of the window causes painting issues with QMenuBar

  • Basically I used the windows API to reverse the layout of the Widget Window (setLayoutDirection only changes the inner layout and does not change the layout for the titlebar). I need this so I can make a multi-language application (I need this for the Arabic languages which have reversed layouts on Windows). I have tried with Qt 4.8.4 (MSVC08, 10, MinGW). Now to explain the issue. When I reverse the layout the menubar is painted correctly, however the menus do not change their direction. For example the highlighted menu in the following picture is when I hover the mouse cursor on the left side of the window. Is this a known bug? Or did I do something wrong?

    Code: (L.E. because it is not clear in the pictures)
    @#include <QApplication>
    #include <QMenuBar>
    #include <QWidget>
    #include <QMenu>
    #include <QAction>
    #include <QLayout>
    #include <Windows.h>

    int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    QWidget *wid = new QWidget();
    QMenuBar *menuBar = new QMenuBar;
    QMenu *menu1 = new QMenu("Menu1");
    QMenu *menu2 = new QMenu("Menu2");
    QAction *act1 = new QAction("Act 1", wid);
    QAction *act2 = new QAction("Act2", wid);
    QVBoxLayout *lay = new QVBoxLayout;
    HWND hWnd = wid->winId();
    long extendedStyle = GetWindowLong(hWnd,GWL_EXSTYLE);
    SetWindowLong(hWnd, GWL_EXSTYLE, extendedStyle | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT);
    return app.exec();


    LIBS += "C:\Program Files\Microsoft SDKs\Windows\v7.0A\lib\User32.lib"

    SOURCES +=
    Thank you in advance.





  • The MSDN library says that with the WS_EX_NOINHERITLAYOUT flag set, the children of the application shouldn't inherit the right to left layout. However this is not the case because the children inherit the layout. Is there any way to disable this using Qt? BTW setting layout direction doesn't change this weird behaviour. I am seeing the same behaviour with all widgets not just the menubar. The problem is that I don't know if it is a Qt problem or a WinAPI issue... Any help would be more than very appreciated.

    "MSDN Source":

  • Basically I'm thinking of reporting this as a bug. Can anyone please tell me if I should or should not do this because I haven't reported any bugs yet and I'm not sure if I should? Thank you.

Log in to reply