Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-11930

Calling QTranslator.load() on a QTranslator object that is already installed in the application makes QApplication.setLayoutDirection() useless

    XMLWordPrintable

Details

    Description

      Calling QTranslator.load() on a QTranslator object that is already installed in the application makes QApplication.setLayoutDirection() useless.

      application.installTranslator(&translator);
      translator.load("somefile");
      application.setLayoutDirection(Qt::RightToLeft);// This will NOT change the direction of the application
      

      Note: QApplication.isRightToLeft() returns true but application is displayed left to right

      To workaround this bug you have to remove the QTranslator from the application before loading the translation file then reinstall the QTranslator.

      Example workaround:

      application.removeTranslator(&translator);
      translator.load("somefile");
      application.installTranslator(&translator);
      

      The following app should be RTL but it is displayed LTR

      #include <QApplication>
      #include <QDialog>
      #include <QHBoxLayout>
      #include <QLabel>
      #include <QTranslator>
      
      int main(int argc, char **argv)
      {
          QApplication app(argc,argv);
          QDialog dialog;
          QHBoxLayout layout;
          QLabel label1("   1   ");
          QLabel label2("   2   ");
          layout.addWidget(&label1);
          layout.addWidget(&label2);
          dialog.setLayout(&layout);
          QTranslator translator;
          app.installTranslator(&translator);
          
          // The following line causes the bug
          translator.load("somefile");
      
          // The following will NOT change the direction of the application
          app.setLayoutDirection(Qt::RightToLeft);
      
          dialog.show();
          return app.exec();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            h.dev H.Dev
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes