PDA

View Full Version : protected function changeevent



fearu
24th September 2010, 22:54
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?

tbscope
25th September 2010, 06:08
Lets have a look at that code:


void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}

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.

fearu
25th September 2010, 13:11
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.