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. [Solved] QGridLayout with two columns
Forum Updated to NodeBB v4.3 + New Features

[Solved] QGridLayout with two columns

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 882 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.
  • H Offline
    H Offline
    Hareen Laks
    wrote on last edited by
    #1

    Hi,
    I have a QStringList and going to create radio buttons and need to put them in a goupbox.

    My String list as below.

    @QStringList Dialog::existingSizes()
    {
    QStringList sizes;
    sizes << "400X1400" << "400X1600" << "400X1800" << "400X2000"<< "600X1400" << "600X1600" << "600X1800" << "600X2000";
    return sizes;
    }@

    And radiobuttons creates as below

    @foreach(size, existingSizes())
    {
    rb = new QRadioButton(size);
    grid->addWidget(rb);
    }
    ui->groupBox->setLayout(grid);@

    I know there is a way to handle the position using column no and raw no.

    But how I get the layout as below.

    @400X1400 600X1400
    400X1600 600X1600
    400X1800 600X1800
    400X2000 600X2000@

    Thanking you.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      something like this?

      filling row-wise from left to right:
      @
      ....

      int colCount = 2;
      QStringList sizeList = existingSizes();
      for(int i = 0; i < sizeList.count(); ++i)
      {
      int row = i / colCount;
      int col = i % colCount;

      QString size = sizeList.value(i);
      rb = new QRadioButton(size);
      grid->addWidget(rb, row, col);
      

      }
      @

      filling col-wise from top to bottom:
      @
      ....

      int rowCount = 4;
      QStringList sizeList = existingSizes();
      for(int i = 0; i < sizeList.count(); ++i)
      {
      int row = i % rowCount;
      int col = i / rowCount;

      QString size = sizeList.value(i);
      rb = new QRadioButton(size);
      grid->addWidget(rb, row, col);
      

      }
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hareen Laks
        wrote on last edited by
        #3

        @raven-worx,

        Thanks a lot. It work as magic. :)

        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