QApp->setLayoutDirection() doesn't work!
-
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(); 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/.
-
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!!! -
[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. -
Wow I asked you about this problem since many months ago and no one found a solution !!!!!
-
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();
}@ -
[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.