Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Find QLayout within QGridLayout
Forum Updated to NodeBB v4.3 + New Features

Find QLayout within QGridLayout

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
13 Posts 4 Posters 1.4k 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.
  • P Offline
    P Offline
    peter-70
    wrote on last edited by peter-70
    #1

    How can I find QLayout within a QGridLayout?
    With a widget is this simple:

    auto index = container->indexOf(widget)
    container->getItemPosition(index, ... etc);
    

    But when I'm searching for a layout within a qgridlayout, how can I do that?
    Many thanks!

    JonBJ 1 Reply Last reply
    0
    • P peter-70

      How can I find QLayout within a QGridLayout?
      With a widget is this simple:

      auto index = container->indexOf(widget)
      container->getItemPosition(index, ... etc);
      

      But when I'm searching for a layout within a qgridlayout, how can I do that?
      Many thanks!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @peter-70
      To find a "parent layout" of a layout, which is what you want, is not straightforward like it is for parent widget. Read https://stackoverflow.com/questions/2409539/getting-parent-layout-in-qt for the solution.

      Ahh, you want it the other way round, you want the find a child layout in a QGridLayout. So http://doc.qt.io/qt-5/qlayout.html#indexOf-1. (Assuming it's a direct child layout, else you have to search recursively.)

      1 Reply Last reply
      1
      • P Offline
        P Offline
        peter-70
        wrote on last edited by
        #3

        QGridLayout::getItemPosition gives me some more informations which I need: http://doc.qt.io/qt-5/qgridlayout.html#getItemPosition.
        But it does not accept an other layout as parameter

        JonBJ 1 Reply Last reply
        0
        • P peter-70

          QGridLayout::getItemPosition gives me some more informations which I need: http://doc.qt.io/qt-5/qgridlayout.html#getItemPosition.
          But it does not accept an other layout as parameter

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @peter-70
          So what is wrong with my:

          So http://doc.qt.io/qt-5/qlayout.html#indexOf-1.

          which gives exactly what you asked for?

          J.HilkJ 1 Reply Last reply
          0
          • JonBJ JonB

            @peter-70
            So what is wrong with my:

            So http://doc.qt.io/qt-5/qlayout.html#indexOf-1.

            which gives exactly what you asked for?

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

            @JonB
            probably the fact that it does not include other Layouts ? ;)

            int QLayout::indexOf(QLayoutItem *layoutItem) const
            Searches for layout item layoutItem in this layout (**not including child layouts**).
            
            Returns the index of layoutItem, or -1 if layoutItem is not found.
            
            This function was introduced in Qt 5.12.
            

            this should work, however it's untested

            for(int i(0); i < container->count(); i++) {
                 QLayout layout* = qobject_cast<QLayout*>(container->itemAt(i));
                 if(layout)
                     qDebug() << "Layout found";
            }
            

            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.

            JonBJ 1 Reply Last reply
            0
            • P Offline
              P Offline
              peter-70
              wrote on last edited by
              #6

              Oh sorry! You're absolutely right, my fault! The problem is only, I have a deprecated version of Qt:
              Qt Creator 4.6.2
              Based on Qt 5.11.1 (Clang 8.0 (Apple), 64 bit)
              Built on Jun 18 2018 11:51:56
              From revision 1ddfb443b6

              So I must renew it and the problem should be away.

              Thank you!

              jsulmJ 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @JonB
                probably the fact that it does not include other Layouts ? ;)

                int QLayout::indexOf(QLayoutItem *layoutItem) const
                Searches for layout item layoutItem in this layout (**not including child layouts**).
                
                Returns the index of layoutItem, or -1 if layoutItem is not found.
                
                This function was introduced in Qt 5.12.
                

                this should work, however it's untested

                for(int i(0); i < container->count(); i++) {
                     QLayout layout* = qobject_cast<QLayout*>(container->itemAt(i));
                     if(layout)
                         qDebug() << "Layout found";
                }
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @J.Hilk

                probably the fact that it does not include other Layouts ? ;)

                Hmm, I thought the docs meant it does include direct child layouts but not "grand-"child layouts. I'm obviously not quite understanding what QLayout::indexOf() is looking at, or I'm not understand what a QLayoutItem is...? [In effect I thought QLayout::indexOf() is doing your loop already itself, I thought it is returning all layouts added via QGridLayout::addLayout.]

                J.HilkJ 1 Reply Last reply
                0
                • JonBJ JonB

                  @J.Hilk

                  probably the fact that it does not include other Layouts ? ;)

                  Hmm, I thought the docs meant it does include direct child layouts but not "grand-"child layouts. I'm obviously not quite understanding what QLayout::indexOf() is looking at, or I'm not understand what a QLayoutItem is...? [In effect I thought QLayout::indexOf() is doing your loop already itself, I thought it is returning all layouts added via QGridLayout::addLayout.]

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

                  @JonB
                  you may be right, I can't test it, as I'm not using 5.12, it's still to buggy!


                  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.

                  P JonBJ 2 Replies Last reply
                  0
                  • J.HilkJ J.Hilk

                    @JonB
                    you may be right, I can't test it, as I'm not using 5.12, it's still to buggy!

                    P Offline
                    P Offline
                    peter-70
                    wrote on last edited by
                    #9

                    @J.Hilk: I know some problems with the Qt software development, but at the moment I dont know what do you mean? What is buggy?

                    J.HilkJ 1 Reply Last reply
                    0
                    • J.HilkJ J.Hilk

                      @JonB
                      you may be right, I can't test it, as I'm not using 5.12, it's still to buggy!

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #10

                      @J.Hilk
                      I wouldn't assume I'm right --- I've never tested/used any of this, I'm just going by documentation...!

                      @peter-70
                      Try mine first 'coz it's simpler :) If it doesn't work, try @J-Hilk's code fragment!

                      1 Reply Last reply
                      0
                      • P peter-70

                        Oh sorry! You're absolutely right, my fault! The problem is only, I have a deprecated version of Qt:
                        Qt Creator 4.6.2
                        Based on Qt 5.11.1 (Clang 8.0 (Apple), 64 bit)
                        Built on Jun 18 2018 11:51:56
                        From revision 1ddfb443b6

                        So I must renew it and the problem should be away.

                        Thank you!

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @peter-70 said in Find QLayout within QGridLayout:

                        Qt Creator 4.6.2
                        Based on Qt 5.11.1 (Clang 8.0 (Apple), 64 bit)

                        This is not necessarily the Qt version you're using, this is the Qt version used to build QtCreator. You should rather check what Qt version you actually installed.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1
                        • P peter-70

                          @J.Hilk: I know some problems with the Qt software development, but at the moment I dont know what do you mean? What is buggy?

                          J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #12

                          @peter-70
                          In my opinion 5.12.0 was rushed to be released during the QtWorldSummit.

                          I'm unable to port any of my projects from 5.11.3 to 5.12 without major changes in the code base for workarounds. Some issues I'm unable to fix without modifying the QtLibary itself.

                          I don't have the time and/or knowledge for that. So I'm staying on 5.11.3 until at least 5.12.1 if not later, it's a LTS-version so bugfixes will keep on coming I asume ;-)


                          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.

                          P 1 Reply Last reply
                          0
                          • J.HilkJ J.Hilk

                            @peter-70
                            In my opinion 5.12.0 was rushed to be released during the QtWorldSummit.

                            I'm unable to port any of my projects from 5.11.3 to 5.12 without major changes in the code base for workarounds. Some issues I'm unable to fix without modifying the QtLibary itself.

                            I don't have the time and/or knowledge for that. So I'm staying on 5.11.3 until at least 5.12.1 if not later, it's a LTS-version so bugfixes will keep on coming I asume ;-)

                            P Offline
                            P Offline
                            peter-70
                            wrote on last edited by
                            #13

                            @J.Hilk Oh, that's silly :-(

                            Thanks for your advice!

                            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