Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Qt layout direction and window title bar
Forum Updated to NodeBB v4.3 + New Features

[Solved] Qt layout direction and window title bar

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 7.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thomas Penin
    wrote on 11 Jan 2011, 10:49 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 11 Jan 2011, 12:39 last edited by
      #2

      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.

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

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Thomas Penin
        wrote on 11 Jan 2011, 12:53 last edited by
        #3

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

        1 Reply Last reply
        0
        • I Offline
          I Offline
          ivan.todorovich
          wrote on 11 Jan 2011, 13:08 last edited by
          #4

          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
          

          }

          @

          o_o Sorry for my rusted english.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dangelog
            wrote on 11 Jan 2011, 15:53 last edited by
            #5

            Feel free to submit a bug report for this.

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

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on 11 Jan 2011, 16:32 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Thomas Penin
                wrote on 11 Jan 2011, 16:51 last edited by
                #7

                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]

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  ivan.todorovich
                  wrote on 11 Jan 2011, 18:11 last edited by
                  #8

                  [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

                  o_o Sorry for my rusted english.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    Thomas Penin
                    wrote on 11 Jan 2011, 18:41 last edited by
                    #9

                    Thanks a lot, ivan. It works!

                    1 Reply Last reply
                    0

                    1/9

                    11 Jan 2011, 10:49

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved