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. QApp->setLayoutDirection() doesn't work!

QApp->setLayoutDirection() doesn't work!

Scheduled Pinned Locked Moved General and Desktop
20 Posts 4 Posters 14.1k Views
  • 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.
  • M Offline
    M Offline
    mbnoimi
    wrote on last edited by
    #2

    Any response guys? do I make myself clear or I've to upload a tiny project?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      msx_br
      wrote on last edited by
      #3

      See this:
      http://stackoverflow.com/questions/3365753/layout-direction-for-arabic-is-not-determined-based-on-the-locale-mac-and-linux

      I hope this can help...

      Just for fun, i created a dialog with a QPushButton with icon:

      @
      ui->pushButton->setIcon(QIcon(":Resources/cirsqr/test1.gif"));
      @

      The text appears in the right side of icon.
      And in the button code:

      @
      void Dialog::on_pushButton_clicked()
      {
      qApp->setLayoutDirection( Qt::RightToLeft );
      }
      @

      And the text appeared in the right side of the icon...

      msx_br - Brazil (Netherlands)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbnoimi
        wrote on last edited by
        #4

        It works fine when I called qApp->setLayoutDirection() from slot but it not works at all when I tried use localize function.... any way I'll try to upload a tiny project explains the problem.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbnoimi
          wrote on last edited by
          #5

          I've created a tiny project to see what happen:
          http://www.mediafire.com/?yjidpetldogdqrs

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mbnoimi
            wrote on last edited by
            #6

            Voila! I found the solution

            @void MainWindow::localize(QString language)
            {
            pLang = language;
            if( translator.load(QString(":/l10n/%1.qm").arg(language)) )
            qApp->installTranslator(&translator);

            if(language == "")
            {
                QLocale loc = QLocale::system();
                language = loc.name();
                qApp->setLayoutDirection(loc.textDirection());
            }
            else
            {
                if(language == "ar")
                    qApp->setLayoutDirection(Qt::RightToLeft);
                else
                    qApp->setLayoutDirection(Qt::LeftToRight);
            }
            

            }@

            It seems that installTranslator makes something EVIL I'll file a bug report about it as soon as "JIRA fix my account":https://qt-project.org/forums/viewthread/15297/.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mbnoimi
              wrote on last edited by
              #7

              Hi guys,

              I tried to change the layout of my application by calling qApp->setLayoutDirection(Qt::RightToLeft); from main window but it didn't apply layout direction!

              How can I fix this issue?

              PS
              I successfully changed the layout when I called setLayoutDirection in main() from main.cpp!!!

              1 Reply Last reply
              0
              • B Offline
                B Offline
                b1gsnak3
                wrote on last edited by
                #8

                if you want to set the layout in the class just use:
                @this->setLayoutDirection(Qt::RightToLeft)@

                Or you can try by accessing the QApplication namespace

                @ QApplication::setLayoutDirection(Qt::RightToLeft) @

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mbnoimi
                  wrote on last edited by
                  #9

                  [quote author="b1gsnak3" date="1359103432"]if you want to set the layout in the class just use:
                  @this->setLayoutDirection(Qt::RightToLeft)@
                  [/quote]
                  It's not working correctly because all the child dialogs don't take their parent layout (it applies "RTL" to "this" while parents still "LTR")

                  [quote author="b1gsnak3" date="1359103432"]Or you can try by accessing the QApplication namespace

                  @ QApplication::setLayoutDirection(Qt::RightToLeft) @[/quote]
                  It doesn't work too it takes qApp behavior.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mbnoimi
                    wrote on last edited by
                    #10

                    I want to send you a tiny project but this forum doesn't support attachments... damn

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mbnoimi
                      wrote on last edited by
                      #11

                      Wow I asked you about this problem since many months ago and no one found a solution !!!!!

                      https://qt-project.org/forums/viewthread/15280/

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mbnoimi
                        wrote on last edited by
                        #12

                        Guys this problem still nagging me could you please help me out to find a solution?

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #13

                          -You're already in a "discussion":/forums/viewthread/24169/ about this in another topic. Please don't run multiple topics on the same issue. I have closed this topic.-
                          After your message, I have decided to merge the topics instead.

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            b1gsnak3
                            wrote on last edited by
                            #14

                            hmm.. this is actually quite weird... When I use layout direction it changes the direction of all of the children of the widget... The only problem I encounter is the titleBar as explained "here":http://qt-project.org/forums/viewthread/24129/#111593 . The problem there is that all of the widgets inherit the layout but the buttons have their clickEvent on the same position as it were LTR layout... This is very weird behaviour.. For me at least...

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mbnoimi
                              wrote on last edited by
                              #15

                              Actually I want to know what if my coding is wrong or right before posting any bug report.

                              Did you review "the project":http://www.mediafire.com/?yjidpetldogdqrs I've sent?
                              [quote author="b1gsnak3" date="1359136423"]hmm.. this is actually quite weird... When I use layout direction it changes the direction of all of the children of the widget... The only problem I encounter is the titleBar as explained "here":http://qt-project.org/forums/viewthread/24129/#111593 . The problem there is that all of the widgets inherit the layout but the buttons have their clickEvent on the same position as it were LTR layout... This is very weird behaviour.. For me at least...[/quote]

                              1 Reply Last reply
                              0
                              • B Offline
                                B Offline
                                b1gsnak3
                                wrote on last edited by
                                #16

                                well... the thing is... that apparently qApp doesn't reload the widget in which you apply the layoutDirection... calling qApp->setLayoutDirection and then this->setLayoutDirection seems to work now... However... As you can see... This doesn't change your titleBar buttons... That is the issue I am currently facing... Apparently you can use the windows API to change the layout of the application but this causes some glitches in the positions of the clickable items (buttons, menus etc)... If the titlebar is not an issue then you can change your topicname to solved :)

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mbnoimi
                                  wrote on last edited by
                                  #17

                                  [quote author="b1gsnak3" date="1359138511"]well... the thing is... that apparently qApp doesn't reload the widget in which you apply the layoutDirection... calling qApp->setLayoutDirection and then this->setLayoutDirection seems to work now[/quote]

                                  No this is incorrect... it applies the layout for the current widget without applying on the called childs... you can see that clearly in this tiny project and this is a snippet from it:

                                  @
                                  if(language == "ar")
                                  {
                                  qApp->setLayoutDirection(Qt::RightToLeft);
                                  this->setLayoutDirection(Qt::RightToLeft);
                                  qDebug("Set RTL");
                                  }
                                  @

                                  I encourage you to take a look into my test which is explaining the whole problem:
                                  http://www.mediafire.com/?10obv3or6mwe81b

                                  [quote]However... As you can see... This doesn't change your titleBar buttons... That is the issue I am currently facing... Apparently you can use the windows API to change the layout of the application but this causes some glitches in the positions of the clickable items (buttons, menus etc)... If the titlebar is not an issue then you can change your topicname to solved :)[/quote]
                                  Actually I don't really interesting in Mirroring of titlebar specially the modifications by Windows API because this is not the way of cross platform developing

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    mbnoimi
                                    wrote on last edited by
                                    #18

                                    There is a temporarily solution by passing the layout to the child manually as following, but this is not a reasonable solution in case I've many dialogs
                                    @void MainWindow::on_pushButton_childDialog_clicked()
                                    {
                                    Dialog dlg(this);
                                    dlg.setLayoutDirection(this->layoutDirection());
                                    dlg.exec();
                                    }@

                                    1 Reply Last reply
                                    0
                                    • B Offline
                                      B Offline
                                      b1gsnak3
                                      wrote on last edited by
                                      #19

                                      well.. in your project i tested it and it worked by just using this->setLayoutDirection after each qApp->setLayoutDirection... in my case it changed the layout for all the children...

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        mbnoimi
                                        wrote on last edited by
                                        #20

                                        [quote author="b1gsnak3" date="1359185402"]well.. in your project i tested it and it worked by just using this->setLayoutDirection after each qApp->setLayoutDirection... in my case it changed the layout for all the children... [/quote]

                                        Could you please post a right to left screentshot for your test shows sub-menus.

                                        1 Reply Last reply
                                        0

                                        • Login

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