QApp->setLayoutDirection() doesn't work!



  • Hi all,

    I've wrote a tiny function for loading the UI translation with suitable application's layout, but I noticed that qApp->setLayoutDirection() not affect on the application!

    What I've to do?

    @void MainWindow::localize(QString language)
    {
    if(language == "")
    {
    QLocale loc = QLocale::system();
    language = loc.name();
    qApp->setLayoutDirection(loc.textDirection());
    qDebug()<<"Text direction:"<<loc.textDirection();
    }
    else
    {
    if(language == "ar")
    {
    qApp->setLayoutDirection(Qt::RightToLeft);
    // A Stupid call makes RightToLeft very ugly
    // foreach (QWidget *widget, QApplication::allWidgets())
    // widget->setLayoutDirection(Qt::RightToLeft);
    }
    else
    {
    qApp->setLayoutDirection(Qt::LeftToRight);
    // foreach (QWidget *widget, QApplication::allWidgets())
    // widget->setLayoutDirection(Qt::LeftToRight);
    }
    }

    if( translator.load(QString(":/l10n/%1.qm").arg(language)) )
        qApp->installTranslator(&translator);
    

    }@

    PS
    The language loads perfectly



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



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



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



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



  • 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&#40;&#41;;
        language = loc.name(&#41;;
        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/.



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



  • 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) @



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



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



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

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



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



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



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



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



  • 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 :)



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



  • 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();
    }@



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


Log in to reply
 

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