Results 1 to 3 of 3

Thread: protected function changeevent

  1. #1
    Join Date
    Aug 2010
    Posts
    15
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default protected function changeevent

    I'm doing a small project in qt creator and it automatically created a protected method changeEvent in MainWindow. Does anyone know its purpose? can I comment it without problems?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: protected function changeevent

    Lets have a look at that code:

    Qt Code:
    1. void MainWindow::changeEvent(QEvent *e)
    2. {
    3. QMainWindow::changeEvent(e);
    4. switch (e->type()) {
    5. case QEvent::LanguageChange:
    6. ui->retranslateUi(this);
    7. break;
    8. default:
    9. break;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    This function gets called when the main window received a change event. This can be all sorts of things, but in this case, the code specifically targets language changes (QEvent::LanguageChange). If the language changed, the UI gets automatically retranslated. Anything else gets handled by the main window itself.

    This is needed because you add custom controls to your window. If you don't react on this change in your main window subclass, only the standard items of the main window get retranslated, but not your own controls.

  3. The following user says thank you to tbscope for this useful post:

    fearu (25th September 2010)

  4. #3
    Join Date
    Aug 2010
    Posts
    15
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: protected function changeevent

    So, if I understood it, by default, qt creates this function to translate the application while it is running, if it occurs the event LanguageChange, but I can use it, adding QEvent::whatever to the case to react to other events that occur on the MainWindow.

    Thanks for your help.

Similar Threads

  1. Replies: 11
    Last Post: 12th July 2009, 16:01
  2. Replies: 2
    Last Post: 22nd January 2008, 15:15
  3. About Password Protected Files:
    By vermarajeev in forum Qt Programming
    Replies: 7
    Last Post: 16th February 2007, 14:46
  4. ALT+TAB & changeEvent
    By munna in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2006, 19:15
  5. Replies: 1
    Last Post: 11th June 2006, 22:25

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.