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. QGridLayout - Row & column

QGridLayout - Row & column

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 2.5k 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.
  • V Offline
    V Offline
    VikramSamy
    wrote on 1 Aug 2018, 03:15 last edited by
    #1

    Hi all

    im using QGridLayout to arrange my widgets, total there is 7 widgets to be arranged, how do i find out how many row and column is allocated when i use Qridlayout?? is it 7x7 (follow number of widgets added) or how??

    ok so i just assumed i want a grid of 5 row and 3 column to arrange the 7 widgets, and then arrange using below code:-

    gridlayout->addWidget(labelC, 0,1,1,1);
    gridlayout->addWidget(bigred, 1,1,1,1);
    gridlayout->addWidget(biggreen, 2,1,1,1);
    gridlayout->addWidget(labelA, 3,0,1,1);
    gridlayout->addWidget(labelB, 3,2,1,1);
    gridlayout->addWidget(smallgreen, 4,0,1,1);
    gridlayout->addWidget(smallred, 4,2,1,1);

    i get as this:-

    0_1533093003061_Qgridlayout.jpg

    as u can see the whole thing not symmetrically arrange, for labelB&smallred still got alot space and the widgets are not pushed to the edge of "blue grid layout borders!!!" but labelA&smallgreen is at near "blue grid layout" border..so how this works?? why the extra space??? and what other things that matters when we decide on the number of rows & columns.

    My actual question is who decided how many row and column that is allocated for a particular Qgridlayout with an A number of widgets. is it we just imagined a logical number of row & column and try to arrange or it automatically set as A x A??

    J 1 Reply Last reply 1 Aug 2018, 05:01
    0
    • V VikramSamy
      1 Aug 2018, 03:15

      Hi all

      im using QGridLayout to arrange my widgets, total there is 7 widgets to be arranged, how do i find out how many row and column is allocated when i use Qridlayout?? is it 7x7 (follow number of widgets added) or how??

      ok so i just assumed i want a grid of 5 row and 3 column to arrange the 7 widgets, and then arrange using below code:-

      gridlayout->addWidget(labelC, 0,1,1,1);
      gridlayout->addWidget(bigred, 1,1,1,1);
      gridlayout->addWidget(biggreen, 2,1,1,1);
      gridlayout->addWidget(labelA, 3,0,1,1);
      gridlayout->addWidget(labelB, 3,2,1,1);
      gridlayout->addWidget(smallgreen, 4,0,1,1);
      gridlayout->addWidget(smallred, 4,2,1,1);

      i get as this:-

      0_1533093003061_Qgridlayout.jpg

      as u can see the whole thing not symmetrically arrange, for labelB&smallred still got alot space and the widgets are not pushed to the edge of "blue grid layout borders!!!" but labelA&smallgreen is at near "blue grid layout" border..so how this works?? why the extra space??? and what other things that matters when we decide on the number of rows & columns.

      My actual question is who decided how many row and column that is allocated for a particular Qgridlayout with an A number of widgets. is it we just imagined a logical number of row & column and try to arrange or it automatically set as A x A??

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 1 Aug 2018, 05:01 last edited by
      #2

      @VikramSamy said in QGridLayout - Row & column:

      how do i find out how many row and column is allocated when i use Qridlayout??

      I don't get the question. It is you who should know how many rows and columns are needed and allocate them.

      The extra space is probably because of margins: http://doc.qt.io/qt-5/qlayout.html#setContentsMargins

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

      V 1 Reply Last reply 3 Aug 2018, 01:37
      2
      • J jsulm
        1 Aug 2018, 05:01

        @VikramSamy said in QGridLayout - Row & column:

        how do i find out how many row and column is allocated when i use Qridlayout??

        I don't get the question. It is you who should know how many rows and columns are needed and allocate them.

        The extra space is probably because of margins: http://doc.qt.io/qt-5/qlayout.html#setContentsMargins

        V Offline
        V Offline
        VikramSamy
        wrote on 3 Aug 2018, 01:37 last edited by
        #3

        @jsulm said in QGridLayout - Row & column:

        @VikramSamy said in QGridLayout - Row & column:

        how do i find out how many row and column is allocated when i use Qridlayout??

        I don't get the question. It is you who should know how many rows and columns are needed and allocate them.

        The extra space is probably because of margins: http://doc.qt.io/qt-5/qlayout.html#setContentsMargins

        ok it means i decided how many row i want and how many columns i want?? is there exist a command to set how many rows and set how many columns?? as u say as i should decide how many columns & rows, so i need to set this beforehand, but how to set?? or the spacing of the widgets will be automatically adjusted according to whatever row & column combination which i can use??

        M 1 Reply Last reply 3 Aug 2018, 04:24
        0
        • V VikramSamy
          3 Aug 2018, 01:37

          @jsulm said in QGridLayout - Row & column:

          @VikramSamy said in QGridLayout - Row & column:

          how do i find out how many row and column is allocated when i use Qridlayout??

          I don't get the question. It is you who should know how many rows and columns are needed and allocate them.

          The extra space is probably because of margins: http://doc.qt.io/qt-5/qlayout.html#setContentsMargins

          ok it means i decided how many row i want and how many columns i want?? is there exist a command to set how many rows and set how many columns?? as u say as i should decide how many columns & rows, so i need to set this beforehand, but how to set?? or the spacing of the widgets will be automatically adjusted according to whatever row & column combination which i can use??

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 3 Aug 2018, 04:24 last edited by
          #4

          @VikramSamy
          Hi
          QGridLayout uses the values you give it with addWidget to
          adjust number of row , col dynamically.
          alt text

          1 Reply Last reply
          3

          1/4

          1 Aug 2018, 03:15

          • Login

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