QGridLayout - Row & column



  • 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??


  • Moderators

    @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



  • @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??


  • Qt Champions 2017

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.