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. Minimum number of Widgets added to a window which have a minimum size
Forum Updated to NodeBB v4.3 + New Features

Minimum number of Widgets added to a window which have a minimum size

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 5 Posters 1.4k Views 2 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.
  • VRoninV VRonin

    Sound a lot like: https://doc.qt.io/qt-6/qtwidgets-layouts-flowlayout-example.html

    Swati777999S Offline
    Swati777999S Offline
    Swati777999
    wrote on last edited by
    #3

    @VRonin said in Minimum number of Widgets added to a window which have a minimum size:

    Sound a lot like: https://doc.qt.io/qt-6/qtwidgets-layouts-flowlayout-example.html

    In my design, I want to have different widgets of the same minimum size, no matter what the size of the window is, they appear in the same size and when the number of widgets/row increases the widgets will get shifted to the rows below.

    Pl45m4P 1 Reply Last reply
    0
    • Swati777999S Swati777999

      @VRonin said in Minimum number of Widgets added to a window which have a minimum size:

      Sound a lot like: https://doc.qt.io/qt-6/qtwidgets-layouts-flowlayout-example.html

      In my design, I want to have different widgets of the same minimum size, no matter what the size of the window is, they appear in the same size and when the number of widgets/row increases the widgets will get shifted to the rows below.

      Pl45m4P Online
      Pl45m4P Online
      Pl45m4
      wrote on last edited by
      #4

      @Swati777999

      That is what FlowLayout should do?! Have you tested it already?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      Swati777999S 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @Swati777999

        That is what FlowLayout should do?! Have you tested it already?

        Swati777999S Offline
        Swati777999S Offline
        Swati777999
        wrote on last edited by
        #5

        @Pl45m4

        Yes, I got its working through the Qt documentation. It's a derived custom layout.
        [I have to include all its files in my project to make it work]I wish it were a pre-defined class of Qt.

        Pl45m4P 1 Reply Last reply
        0
        • Swati777999S Swati777999

          @Pl45m4

          Yes, I got its working through the Qt documentation. It's a derived custom layout.
          [I have to include all its files in my project to make it work]I wish it were a pre-defined class of Qt.

          Pl45m4P Online
          Pl45m4P Online
          Pl45m4
          wrote on last edited by
          #6

          @Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:

          I wish it were a pre-defined class of Qt.

          If you take the FlowLayout.cpp and FlowLayout.h from the example and create a new class in your project, you can use it, like it has always been there :)


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          Swati777999S 2 Replies Last reply
          1
          • Pl45m4P Pl45m4

            @Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:

            I wish it were a pre-defined class of Qt.

            If you take the FlowLayout.cpp and FlowLayout.h from the example and create a new class in your project, you can use it, like it has always been there :)

            Swati777999S Offline
            Swati777999S Offline
            Swati777999
            wrote on last edited by
            #7
            This post is deleted!
            1 Reply Last reply
            0
            • Pl45m4P Pl45m4

              @Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:

              I wish it were a pre-defined class of Qt.

              If you take the FlowLayout.cpp and FlowLayout.h from the example and create a new class in your project, you can use it, like it has always been there :)

              Swati777999S Offline
              Swati777999S Offline
              Swati777999
              wrote on last edited by
              #8

              @Pl45m4
              LayoutExample_Qt.PNG

              If I add flowlayout.h in headers of Layout class and flowlayout.cpp in the sources of Layout class , will it not work?

              jsulmJ Pl45m4P 2 Replies Last reply
              0
              • Swati777999S Swati777999

                @Pl45m4
                LayoutExample_Qt.PNG

                If I add flowlayout.h in headers of Layout class and flowlayout.cpp in the sources of Layout class , will it not work?

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

                @Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:

                will it not work?

                Why should it not work?
                Why don't you simply try? It is faster than waiting in forum for a response...

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

                Swati777999S 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:

                  will it not work?

                  Why should it not work?
                  Why don't you simply try? It is faster than waiting in forum for a response...

                  Swati777999S Offline
                  Swati777999S Offline
                  Swati777999
                  wrote on last edited by
                  #10

                  @jsulm

                  Yes, I am trying with flowLayout instead of GridLayout, I couldn't see flow Layout working in the way it is expected to work.

                  jsulmJ 1 Reply Last reply
                  0
                  • Swati777999S Swati777999

                    @jsulm

                    Yes, I am trying with flowLayout instead of GridLayout, I couldn't see flow Layout working in the way it is expected to work.

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

                    @Swati777999 As long as you don't provide more information others can only guess...

                    1. Show your code
                    2. Explain how exactly it misbehaves

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

                    Swati777999S 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @Swati777999 As long as you don't provide more information others can only guess...

                      1. Show your code
                      2. Explain how exactly it misbehaves
                      Swati777999S Offline
                      Swati777999S Offline
                      Swati777999
                      wrote on last edited by
                      #12

                      @jsulm

                      See the following code.
                      The reason for using QMap is that I've become familiar with it . I've not tried arrays with QVector.

                           int n=20;
                          QGridLayout *mSDLayout = new QGridLayout();
                          QMap <int,QWidget*>dTWidgets;
                          QMap <int, QLabel*>Names;
                          QMap <int ,QTableWidget *> dTs;
                      
                          FlowLayout *flowLayout=new FlowLayout(); // Parent Layout
                      
                            for (int ii=0;ii<n;ii++)
                              {
                      
                                dTWidgets[ii] =new QWidget();  
                      
                      //          mSDLayout->addWidget(dTWidgets[ii],0,ii);
                                mSDLayout->addWidget(dTWidgets[ii],0,ii,Qt::AlignCenter);
                      
                      
                                Names[ii] =new QLabel(QString("Name %1").arg(ii+1));
                      
                                flowLayout->addWidget(Names[ii]);
                                flowLayout->setAlignment(Names[ii],Qt::AlignHCenter);
                      
                                dTs[ii] = new QTableWidget(); 
                                flowLayout->addWidget(dTs[ii]);
                                dTWidgets[ii]->setLayout(flowLayout);
                      

                      This code gives me following result-
                      SingleFLayout.PNG

                      JKSHJ 1 Reply Last reply
                      0
                      • Swati777999S Swati777999

                        @jsulm

                        See the following code.
                        The reason for using QMap is that I've become familiar with it . I've not tried arrays with QVector.

                             int n=20;
                            QGridLayout *mSDLayout = new QGridLayout();
                            QMap <int,QWidget*>dTWidgets;
                            QMap <int, QLabel*>Names;
                            QMap <int ,QTableWidget *> dTs;
                        
                            FlowLayout *flowLayout=new FlowLayout(); // Parent Layout
                        
                              for (int ii=0;ii<n;ii++)
                                {
                        
                                  dTWidgets[ii] =new QWidget();  
                        
                        //          mSDLayout->addWidget(dTWidgets[ii],0,ii);
                                  mSDLayout->addWidget(dTWidgets[ii],0,ii,Qt::AlignCenter);
                        
                        
                                  Names[ii] =new QLabel(QString("Name %1").arg(ii+1));
                        
                                  flowLayout->addWidget(Names[ii]);
                                  flowLayout->setAlignment(Names[ii],Qt::AlignHCenter);
                        
                                  dTs[ii] = new QTableWidget(); 
                                  flowLayout->addWidget(dTs[ii]);
                                  dTWidgets[ii]->setLayout(flowLayout);
                        

                        This code gives me following result-
                        SingleFLayout.PNG

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

                        @Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:

                        The reason for using QMap is that I've become familiar with it . I've not tried arrays with QVector.

                        • A vector is an array.
                        • A map is not an array.
                        dTWidgets[ii]->setLayout(flowLayout);
                        

                        Tell us:

                        1. Which which should this layout belong to?
                        2. Which widget is your top-level widget?

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

                        Swati777999S 1 Reply Last reply
                        2
                        • Swati777999S Swati777999

                          @Pl45m4
                          LayoutExample_Qt.PNG

                          If I add flowlayout.h in headers of Layout class and flowlayout.cpp in the sources of Layout class , will it not work?

                          Pl45m4P Online
                          Pl45m4P Online
                          Pl45m4
                          wrote on last edited by
                          #14

                          @Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:

                          If I add flowlayout.h in headers of Layout class and flowlayout.cpp in the sources of Layout class , will it not work?

                          Layout is your project name, not your class.
                          LayoutExample is your class name, judging from your header and code file.
                          What does this file include? Is it the whole FlowLayoutExample or just the FlowLayout class taken from there?


                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          1 Reply Last reply
                          0
                          • JKSHJ JKSH

                            @Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:

                            The reason for using QMap is that I've become familiar with it . I've not tried arrays with QVector.

                            • A vector is an array.
                            • A map is not an array.
                            dTWidgets[ii]->setLayout(flowLayout);
                            

                            Tell us:

                            1. Which which should this layout belong to?
                            2. Which widget is your top-level widget?
                            Swati777999S Offline
                            Swati777999S Offline
                            Swati777999
                            wrote on last edited by
                            #15

                            @JKSH said in Minimum number of Widgets added to a window which have a minimum size:

                            @Swati777999 said in Minimum number of Widgets added to a window which have a minimum size:

                            The reason for using QMap is that I've become familiar with it . I've not tried arrays with QVector.

                            • A vector is an array.
                            • A map is not an array.
                            dTWidgets[ii]->setLayout(flowLayout);
                            

                            Tell us:

                            1. Which which should this layout belong to?

                            FlowLayout *flowLayout=new FlowLayout(); // Parent Layout
                            Flow Layout Example from Qt documentation
                            I've included flowlayout.h and flowlayout.cpp in the headers and sources of Layout project.
                            Layout_Project.PNG

                            1. Which widget is your top-level widget?
                              QWidget *mSWidget = new QWidget(this);
                              QVBoxLayout *mSLayout=new QVBoxLayout(mSWidget);
                              mSWidget ->setLayout(mSLayout);

                            actually it's the outer level box to which an inner level layout is added , now I am focussed on the inner level design which should look like
                            Layout_Example7.PNG
                            To FlowLayout ,these units are added as widgets.

                            I hope that I explained it well.

                            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