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. Equally spaced tables in a layout

Equally spaced tables in a layout

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 504 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.
  • Swati777999S Offline
    Swati777999S Offline
    Swati777999
    wrote on last edited by Swati777999
    #1

    Hi All,

    I want to get equally spaced tables in my design. I've written the following code but it produces incrementally spaced tables.

    Layout_Example7.PNG
    How can I achieve my desired design?

     QMap <int,QWidget*>dTWidgets;
     QMap<int ,QGridLayout*>tGLayout;
     QMap <int, QLabel*>dNames;
     QMap <int ,QTableWidget *> dTs;
     QGridLayout *msDLayout =new QGridLayout();
     int n=10;
     for (int ii=0;ii<n;ii++)
            {
    
              dTWidgets[ii] =new QWidget();    //Parent Widget
              mSDLayout->addWidget(dTWidgets[ii],0,ii,Qt::AlignCenter);
              tGLayout[ii]=new QGridLayout();   //Parent Layout
              dTWidgets[ii]->setLayout(tGLayout[ii]);
    
    
              dNames[ii] =new QLabel(QString("Name %1").arg(ii));  //Child-1 of Parent
              tGLayout[ii]->addWidget(dNames[ii],0,ii);
              tGLayout[ii]->setAlignment(dNames[ii],Qt::AlignHCenter);
              
              dTs[ii] = new QTableWidget(); //Child-2 of Parent
              tGLayout[ii]->addWidget(dTs[ii]);
    ``
    

    It produces tables with unequal spaces between them and the labels for names of each table don't align with each table.Can someone suggest me how to rectify erorrs from the above code?

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

    Pl45m4P 1 Reply Last reply
    0
    • Swati777999S Swati777999

      Hi All,

      I want to get equally spaced tables in my design. I've written the following code but it produces incrementally spaced tables.

      Layout_Example7.PNG
      How can I achieve my desired design?

       QMap <int,QWidget*>dTWidgets;
       QMap<int ,QGridLayout*>tGLayout;
       QMap <int, QLabel*>dNames;
       QMap <int ,QTableWidget *> dTs;
       QGridLayout *msDLayout =new QGridLayout();
       int n=10;
       for (int ii=0;ii<n;ii++)
              {
      
                dTWidgets[ii] =new QWidget();    //Parent Widget
                mSDLayout->addWidget(dTWidgets[ii],0,ii,Qt::AlignCenter);
                tGLayout[ii]=new QGridLayout();   //Parent Layout
                dTWidgets[ii]->setLayout(tGLayout[ii]);
      
      
                dNames[ii] =new QLabel(QString("Name %1").arg(ii));  //Child-1 of Parent
                tGLayout[ii]->addWidget(dNames[ii],0,ii);
                tGLayout[ii]->setAlignment(dNames[ii],Qt::AlignHCenter);
                
                dTs[ii] = new QTableWidget(); //Child-2 of Parent
                tGLayout[ii]->addWidget(dTs[ii]);
      ``
      

      It produces tables with unequal spaces between them and the labels for names of each table don't align with each table.Can someone suggest me how to rectify erorrs from the above code?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Swati777999

      For what purpose are those QMaps?

      If you use layouts, the size is dynamic in shrinks or expands with your parent widget. How should it look like?

      Edit:

      After your edit, I see your attached image.
      If you just want this stucture, you dont need a GridLayout. You can use a verticalLayout and put your widgets below each other


      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

        For what purpose are those QMaps?

        If you use layouts, the size is dynamic in shrinks or expands with your parent widget. How should it look like?

        Edit:

        After your edit, I see your attached image.
        If you just want this stucture, you dont need a GridLayout. You can use a verticalLayout and put your widgets below each other

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

        @Pl45m4
        It should be like this [ orange border is for the layout]
        Layout_Example7.PNG

        I have used QMap for creating an array of widgets.

        “ In order to be irreplaceable, one must always be different” – Coco Chanel

        Pl45m4P 1 Reply Last reply
        0
        • Swati777999S Swati777999

          @Pl45m4
          It should be like this [ orange border is for the layout]
          Layout_Example7.PNG

          I have used QMap for creating an array of widgets.

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

          @Swati777999 said in Equally spaced tables in a layout:

          I have used QMap for creating an array of widgets.

          But why?! Do you really need that int value mapped to each widget?
          If you just need to store multiple widgets in an array, better use containers like QVector.

          Edit:
          The QMap documentation also states that you should access the map content with .value(i) or .key(i) insteas of map[i].
          Especially when you compare things or look for a value in your map.

          • https://doc.qt.io/qt-5/qmap.html#details

          You could create a widget, assign a layout (like vBox) and add your stuff... You can do this multiple time in a loop and add the new widget to a QVector<QWidget*> (or QMap, if you really want to).


          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 said in Equally spaced tables in a layout:

            I have used QMap for creating an array of widgets.

            But why?! Do you really need that int value mapped to each widget?
            If you just need to store multiple widgets in an array, better use containers like QVector.

            Edit:
            The QMap documentation also states that you should access the map content with .value(i) or .key(i) insteas of map[i].
            Especially when you compare things or look for a value in your map.

            • https://doc.qt.io/qt-5/qmap.html#details

            You could create a widget, assign a layout (like vBox) and add your stuff... You can do this multiple time in a loop and add the new widget to a QVector<QWidget*> (or QMap, if you really want to).

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

            @Pl45m4 said in Equally spaced tables in a layout:

            @Swati777999 said in Equally spaced tables in a layout:
            You could create a widget, assign a layout (like vBox) and add your stuff... You can do this multiple time in a loop and add the new widget to a QVector<QWidget*> (or QMap, if you really want to).

            I have just done the other way. I have created the array first, then created widgets and layouts for the individual box widgets. Does sequencing of steps in a particular manner affect the end result?

            “ In order to be irreplaceable, one must always be different” – Coco Chanel

            Pl45m4P 1 Reply Last reply
            0
            • Swati777999S Swati777999

              @Pl45m4 said in Equally spaced tables in a layout:

              @Swati777999 said in Equally spaced tables in a layout:
              You could create a widget, assign a layout (like vBox) and add your stuff... You can do this multiple time in a loop and add the new widget to a QVector<QWidget*> (or QMap, if you really want to).

              I have just done the other way. I have created the array first, then created widgets and layouts for the individual box widgets. Does sequencing of steps in a particular manner affect the end result?

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

              @Swati777999

              The order when you create what doesn't matter, as long as you assign it correctly after everything is created. Of course you can't assign the widget to your array without creating it first.


              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
              1

              • Login

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