Results 1 to 10 of 10

Thread: Main Window initialisation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Main Window initialisation

    Can you prepare and attach compilable example (I mean all needed files, .cpp, .h and .ui) so we can test it ?
    edit:
    and can you verify that LanguageChange event is not triggered ? I think all strings will be replaced to defaults set in designer if you call ui->retranslateUi(), you should place all setText(), setTitle() etc. code to be called in event handler in case of LanguageChange event.
    Last edited by stampede; 4th July 2011 at 19:29.

  2. #2
    Join Date
    May 2011
    Posts
    17
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Main Window initialisation

    Hi,

    Here are the files.

    Yes the retranslate is the problem. This is automatically generated by Qt creator wizard and it did not bother me until now.

    I am not quite sure yet to understand the way that this language event loop works or the possible benefits for my gui. My gui is intended to a scientific audience who use english as main working/communication language so I would comment out this retranslate command for the time being.
    Attached Files Attached Files

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Main Window initialisation

    You don't have to comment out anything, just set new strings and window titles in event handler during LanguageChange event:
    Qt Code:
    1. void MainWindow::changeEvent(QEvent *e)
    2. {
    3. QMainWindow::changeEvent(e);
    4. switch (e->type()) {
    5. case QEvent::LanguageChange:
    6. this->retranslate();
    7. break;
    8. default:
    9. break;
    10. }
    11. }
    12.  
    13. void MainWindow::retranslate(){
    14. ui->retranslateUi(this);
    15. ui->pushButton->setText(tr("I changed the text"));
    16. setWindowTitle(tr("This is the title I would like to be"));
    17. }
    To copy to clipboard, switch view to plain text mode 
    In constructor call this->retranslate() and its done.

Similar Threads

  1. Replies: 2
    Last Post: 17th February 2011, 12:30
  2. Replies: 3
    Last Post: 23rd December 2010, 06:55
  3. Replies: 9
    Last Post: 16th May 2010, 16:21
  4. Replies: 11
    Last Post: 11th August 2008, 09:14
  5. Replies: 15
    Last Post: 23rd March 2007, 16:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.