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. All widets list on a widget

All widets list on a widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 6.2k Views
  • 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
    ShinSat
    wrote on last edited by ShinSat
    #1

    Hi All,

    A quick quesiton.
    Is there any way to get all widgets on a specific widget, which is the lowest base widget, in pyQt5?
    I tried findChildren but it requres a search widget name string as a parameter such as QPushButton. Why it doesn't work with just empty string???

    Many thanks for your help.
    Sat

    JKSHJ 1 Reply Last reply
    0
    • S ShinSat

      Hi All,

      A quick quesiton.
      Is there any way to get all widgets on a specific widget, which is the lowest base widget, in pyQt5?
      I tried findChildren but it requres a search widget name string as a parameter such as QPushButton. Why it doesn't work with just empty string???

      Many thanks for your help.
      Sat

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi @ShinSat,

      Are all of your child widgets in a layout? If so, you can call QLayout::itemAt() followed by QLayoutItem::widget().

      I'm not sure if these methods are available in PyQt or not.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      S 1 Reply Last reply
      2
      • JKSHJ JKSH

        Hi @ShinSat,

        Are all of your child widgets in a layout? If so, you can call QLayout::itemAt() followed by QLayoutItem::widget().

        I'm not sure if these methods are available in PyQt or not.

        S Offline
        S Offline
        ShinSat
        wrote on last edited by
        #3

        @JKSH Thanks for an update. Some children are NOT in layout. :<

        Sat

        JKSHJ J.HilkJ 2 Replies Last reply
        0
        • S ShinSat

          @JKSH Thanks for an update. Some children are NOT in layout. :<

          Sat

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by JKSH
          #4

          @ShinSat said in All widets list on a widget:

          @JKSH Thanks for an update. Some children are NOT in layout. :<

          I can't think of a way to get a non-layouted child without specifying its type, sorry.

          May I ask why you want to get all the child widgets?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • S ShinSat

            @JKSH Thanks for an update. Some children are NOT in layout. :<

            Sat

            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @ShinSat I could think of a very, time-consuming way to list all widgets.
            If you need to create the list once, than this could be fine. And its in c++ as I don't use pyqt

            QList<QWidget *> listOfWidgets;
            
            
            int width(targetwidget->width());
            int height(targetwidget->height());
            
            for(int x(0); x < width; x++){
                for(int y(0); y < height; y++){
                    QWidget *w = targetwidget->childAt(x,y);
                    if(w && !listOfWidgets.contains(w))
                         listOfWidgets.append(w);
                }
            }
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            JKSHJ 1 Reply Last reply
            2
            • J.HilkJ J.Hilk

              @ShinSat I could think of a very, time-consuming way to list all widgets.
              If you need to create the list once, than this could be fine. And its in c++ as I don't use pyqt

              QList<QWidget *> listOfWidgets;
              
              
              int width(targetwidget->width());
              int height(targetwidget->height());
              
              for(int x(0); x < width; x++){
                  for(int y(0); y < height; y++){
                      QWidget *w = targetwidget->childAt(x,y);
                      if(w && !listOfWidgets.contains(w))
                           listOfWidgets.append(w);
                  }
              }
              
              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              @J.Hilk said in All widets list on a widget:

              @ShinSat I could think of a very, time-consuming way to list all widgets.
              If you need to create the list once, than this could be fine. And its in c++ as I don't use pyqt

              QList<QWidget *> listOfWidgets;
              
              
              int width(targetwidget->width());
              int height(targetwidget->height());
              
              for(int x(0); x < width; x++){
                  for(int y(0); y < height; y++){
                      QWidget *w = targetwidget->childAt(x,y);
                      if(w && !listOfWidgets.contains(w))
                           listOfWidgets.append(w);
                  }
              }
              

              Haha!

              This assumes that all child widgets are already visible.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • S Offline
                S Offline
                ShinSat
                wrote on last edited by ShinSat
                #7

                Thank you very much for sharing various ideas!

                Well, let me share what I'm trying.
                I want to save the app window(widgets) structure, which includes both horizontal and vertical hierarchy.
                The app consists of multiple widgets on one MAIN widget.
                By saving the structure when the app shut down, the app can restore every widget during the startup(the same widget layout).
                I think the most challenging part is to get and list all vertical structure, which can be dynamically changed by the user in runtime.

                Sat

                J.HilkJ JKSHJ 2 Replies Last reply
                0
                • S ShinSat

                  Thank you very much for sharing various ideas!

                  Well, let me share what I'm trying.
                  I want to save the app window(widgets) structure, which includes both horizontal and vertical hierarchy.
                  The app consists of multiple widgets on one MAIN widget.
                  By saving the structure when the app shut down, the app can restore every widget during the startup(the same widget layout).
                  I think the most challenging part is to get and list all vertical structure, which can be dynamically changed by the user in runtime.

                  Sat

                  J.HilkJ Online
                  J.HilkJ Online
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @ShinSat Well the easiest way would probably be to create your own base class. That includes or inherits from QSettings.

                  in the Destructor you save all relevent data via QSettings, visible, x, y, width, height etc and in the constructor you load them via QSettings.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  1
                  • S ShinSat

                    Thank you very much for sharing various ideas!

                    Well, let me share what I'm trying.
                    I want to save the app window(widgets) structure, which includes both horizontal and vertical hierarchy.
                    The app consists of multiple widgets on one MAIN widget.
                    By saving the structure when the app shut down, the app can restore every widget during the startup(the same widget layout).
                    I think the most challenging part is to get and list all vertical structure, which can be dynamically changed by the user in runtime.

                    Sat

                    JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #9

                    @ShinSat said in All widets list on a widget:

                    Well, let me share what I'm trying.
                    I want to save the app window(widgets) structure, which includes both horizontal and vertical hierarchy.
                    The app consists of multiple widgets on one MAIN widget.
                    By saving the structure when the app shut down, the app can restore every widget during the startup(the same widget layout).
                    I think the most challenging part is to get and list all vertical structure, which can be dynamically changed by the user in runtime.

                    Have a look at:

                    • QWidget::saveGeometry()/QWidget::restoreGeometry()
                    • QMainWindow::saveState()/QMainWindow::restoreState()

                    Are these enough to fully save/restore your widget?

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    S 1 Reply Last reply
                    2
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi
                      Just as a note. findChildren does work without using a name.

                      QList<QPushButton *> allPButtons = parentWidget.findChildren<QPushButton *>();
                      

                      also no name is not like
                      parentWidget.findChildren<QPushButton *>(""); // its an empty name
                      That would be empty name.
                      No name is
                      parentWidget.findChildren<QPushButton *>(QString()); // this is truely "no name"
                      which is default param.

                      S 1 Reply Last reply
                      3
                      • JKSHJ JKSH

                        @ShinSat said in All widets list on a widget:

                        Well, let me share what I'm trying.
                        I want to save the app window(widgets) structure, which includes both horizontal and vertical hierarchy.
                        The app consists of multiple widgets on one MAIN widget.
                        By saving the structure when the app shut down, the app can restore every widget during the startup(the same widget layout).
                        I think the most challenging part is to get and list all vertical structure, which can be dynamically changed by the user in runtime.

                        Have a look at:

                        • QWidget::saveGeometry()/QWidget::restoreGeometry()
                        • QMainWindow::saveState()/QMainWindow::restoreState()

                        Are these enough to fully save/restore your widget?

                        S Offline
                        S Offline
                        ShinSat
                        wrote on last edited by ShinSat
                        #11

                        Have a look at:

                        QWidget::saveGeometry()/QWidget::restoreGeometry()
                        QMainWindow::saveState()/QMainWindow::restoreState()

                        Are these enough to fully save/restore your widget?

                        @JKSH
                        Actually, I also need to save/restore the app's horizontal and vertical hierarchy.
                        Since the hierarchy is something like widgets on widget on widget on widget ,,,, I would like to find out how I can achieve it in Qt(in my env, it's pyqt5.9) :)
                        findChildren() is probably the only way to achieve that?, I'm still testing, though...
                        I can't find a right direction so far. :<

                        Sat

                        1 Reply Last reply
                        0
                        • mrjjM mrjj

                          Hi
                          Just as a note. findChildren does work without using a name.

                          QList<QPushButton *> allPButtons = parentWidget.findChildren<QPushButton *>();
                          

                          also no name is not like
                          parentWidget.findChildren<QPushButton *>(""); // its an empty name
                          That would be empty name.
                          No name is
                          parentWidget.findChildren<QPushButton *>(QString()); // this is truely "no name"
                          which is default param.

                          S Offline
                          S Offline
                          ShinSat
                          wrote on last edited by
                          #12

                          @mrjj said in All widets list on a widget:

                          parentWidget.findChildren<QPushButton *>(QString()); // this is truely "no name"

                          AFAIK, QString() is not available in pyqt5, but I'll double check that. :)

                          Thanks,
                          Sat

                          mrjjM 1 Reply Last reply
                          0
                          • S ShinSat

                            @mrjj said in All widets list on a widget:

                            parentWidget.findChildren<QPushButton *>(QString()); // this is truely "no name"

                            AFAIK, QString() is not available in pyqt5, but I'll double check that. :)

                            Thanks,
                            Sat

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by mrjj
                            #13

                            @ShinSat
                            ok?
                            Its default value for name paramter so maybe just leave it out completely as in

                            no "" for name.
                            
                            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