Access all dialogs of application

  • Hi there

    I've been developing a multilingual application that could change ui language in runtime. I do this:
    namespace Global
    extern Application* application;
    extern QList<QWidget*> allDialogs;
    and connected change language slots to corresponding slots (they call Global::application->installTranslator... ).
    everything works: all of dialogs are translated during runtime.
    Also directions of all dialog need to be changed for RTL languages like Arabic and Persian. Couldn't find a way to access all dialogs and main windows of an application, so I add them in their ctors to a global QList<QWidget*> and setLayoutDirection(Qt::RightToLeft) there.

    Is there a better way to access all dialogs and their children and children of children and .... ?

  • you can use QWidgetList QApplication::topLevelWidgets ()

  • And for none-top Levels?
    Is it possible to iterate over a structure (perhaps something like STL iterators) to visit each dialog in program?

  • The non-toplevels are children of toplevels, iterate over the QObject::children() list or use the QObject::findChildren() methods to find children of a certain type (class).

  • Thank you. It works well.

    I write a subclass of QDialog and add retranslateUI method to it. that method simply calls ui->retranslateUi(). I subclass all my dialogs from it. iterating over children of main window of type DialogProxy*, program calls that method:
    QList<DialogProxy*> list = this->findChildren<DialogProxy*>();
    for(int i=0; i<list.size(); i++)>retraslateUI();
    when clicking on the change language menu item all open dialogs are translated.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.