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. Access all dialogs of application
Qt 6.11 is out! See what's new in the release blog

Access all dialogs of application

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.9k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    soroush
    wrote on last edited by
    #1

    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 .... ?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      you can use QWidgetList QApplication::topLevelWidgets ()

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        soroush
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          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).

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • S Offline
            S Offline
            soroush
            wrote on last edited by
            #5

            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++)
            list.at(i)->retraslateUI();
            @
            when clicking on the change language menu item all open dialogs are translated.

            1 Reply Last reply
            0

            • Login

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