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. QMenu And QSqlQueryModel translation problem !
QtWS25 Last Chance

QMenu And QSqlQueryModel translation problem !

Scheduled Pinned Locked Moved Solved General and Desktop
qmenuqsqltablemodelqtranslatorproblemqt5.15.2
5 Posts 3 Posters 846 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.
  • P Offline
    P Offline
    Proton Phoenix
    wrote on 27 Feb 2023, 18:29 last edited by Proton Phoenix
    #1

    Hi ~ I am using Qt 5.15.2 , in my test software everything being translated successfully! except QMenu And QSqlTableModel
    This is an example how i am using both

    First QMenu:

    mainsettingsMenu=new QMenu(this);
       custom1=new QAction(QObject::tr("م 1"),this);
       custom2=new QAction(tr("م 2"),this);
       custom3=new QAction(tr("م 3"),this);
       custom4=new QAction(tr("م 4"),this);
       custom5=new QAction(tr("م 5"),this);
       mainsettingsMenu->addAction(custom1);
       mainsettingsMenu->addAction(custom2);
       mainsettingsMenu->addAction(custom3);
       mainsettingsMenu->addAction(custom4);
       mainsettingsMenu->addAction(custom5);
      
              );
       ui->settingsbtn->setMenu(mainsettingsMenu);
    

    Second QSqlTableModel :

    test=new QSqlTableModel(this);
    test->setTable("testTable");
        test->select();
        test->setFilter(filter);
        ui->tableView->setModel(test);
        test->setHeaderData(1, Qt::Horizontal, tr("م 1"));
        test->setHeaderData(2, Qt::Horizontal, tr("م 2"));
        test->setHeaderData(3, Qt::Horizontal, tr("م 3"));
        test->setHeaderData(4, Qt::Horizontal, tr("م 4"));
        test->setHeaderData(5, Qt::Horizontal, tr("م 5"));
        test->setHeaderData(6, Qt::Horizontal, tr("م 6"));
    

    i am using those to reload translations ...

    QApplication::installTranslator(&translator);
      // qApp->installTranslator(&translator);
    
       ui->retranslateUi(this);
    

    By The way i am translating from Unicode language to French ... everything works , except those two ...

    C 1 Reply Last reply 27 Feb 2023, 18:32
    0
    • P Proton Phoenix
      27 Feb 2023, 18:29

      Hi ~ I am using Qt 5.15.2 , in my test software everything being translated successfully! except QMenu And QSqlTableModel
      This is an example how i am using both

      First QMenu:

      mainsettingsMenu=new QMenu(this);
         custom1=new QAction(QObject::tr("م 1"),this);
         custom2=new QAction(tr("م 2"),this);
         custom3=new QAction(tr("م 3"),this);
         custom4=new QAction(tr("م 4"),this);
         custom5=new QAction(tr("م 5"),this);
         mainsettingsMenu->addAction(custom1);
         mainsettingsMenu->addAction(custom2);
         mainsettingsMenu->addAction(custom3);
         mainsettingsMenu->addAction(custom4);
         mainsettingsMenu->addAction(custom5);
        
                );
         ui->settingsbtn->setMenu(mainsettingsMenu);
      

      Second QSqlTableModel :

      test=new QSqlTableModel(this);
      test->setTable("testTable");
          test->select();
          test->setFilter(filter);
          ui->tableView->setModel(test);
          test->setHeaderData(1, Qt::Horizontal, tr("م 1"));
          test->setHeaderData(2, Qt::Horizontal, tr("م 2"));
          test->setHeaderData(3, Qt::Horizontal, tr("م 3"));
          test->setHeaderData(4, Qt::Horizontal, tr("م 4"));
          test->setHeaderData(5, Qt::Horizontal, tr("م 5"));
          test->setHeaderData(6, Qt::Horizontal, tr("م 6"));
      

      i am using those to reload translations ...

      QApplication::installTranslator(&translator);
        // qApp->installTranslator(&translator);
      
         ui->retranslateUi(this);
      

      By The way i am translating from Unicode language to French ... everything works , except those two ...

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 27 Feb 2023, 18:32 last edited by Christian Ehrlicher
      #2

      retranslateUi() can only change the texts on the widgets the ui file created. How should it e.g. access a QSqlTableModel (and know what text you've set somewhere)? You have to set the new texts by yourself.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      P 1 Reply Last reply 27 Feb 2023, 18:36
      1
      • C Christian Ehrlicher
        27 Feb 2023, 18:32

        retranslateUi() can only change the texts on the widgets the ui file created. How should it e.g. access a QSqlTableModel (and know what text you've set somewhere)? You have to set the new texts by yourself.

        P Offline
        P Offline
        Proton Phoenix
        wrote on 27 Feb 2023, 18:36 last edited by
        #3

        @Christian-Ehrlicher said in QMenu And QSqlQueryModel translation problem !:

        retranslateUi() can only change the texts on the widgets the ui file created. How should it e.g. access a QSqlTableModel (and know what text you've set somehwere)? You have to set the new texts by yourself.

        Thank you bro ... when i saw QtLinguist gives the power to edit those texts there .. i thought Qt Can Handle it somehow ...
        Thank you so much ^^ <3

        S 1 Reply Last reply 27 Feb 2023, 19:21
        1
        • P Proton Phoenix has marked this topic as solved on 27 Feb 2023, 18:36
        • P Proton Phoenix
          27 Feb 2023, 18:36

          @Christian-Ehrlicher said in QMenu And QSqlQueryModel translation problem !:

          retranslateUi() can only change the texts on the widgets the ui file created. How should it e.g. access a QSqlTableModel (and know what text you've set somehwere)? You have to set the new texts by yourself.

          Thank you bro ... when i saw QtLinguist gives the power to edit those texts there .. i thought Qt Can Handle it somehow ...
          Thank you so much ^^ <3

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 27 Feb 2023, 19:21 last edited by
          #4

          @Proton-Phoenix Hi,

          One way to handle it is to act on the QEvent::LanguageChange event so you can trigger the re-translation of your UI.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply 27 Feb 2023, 20:57
          1
          • S SGaist
            27 Feb 2023, 19:21

            @Proton-Phoenix Hi,

            One way to handle it is to act on the QEvent::LanguageChange event so you can trigger the re-translation of your UI.

            P Offline
            P Offline
            Proton Phoenix
            wrote on 27 Feb 2023, 20:57 last edited by Proton Phoenix
            #5

            @SGaist said in QMenu And QSqlQueryModel translation problem !:

            QEvent::LanguageChange
            @

            SGaist Hi bro <3

            i didn't know about QEvent::LanguageChange before really thank you, i will check it <3

            1 Reply Last reply
            0

            1/5

            27 Feb 2023, 18:29

            • Login

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