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. Arranging the grid layout in function

Arranging the grid layout in function

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 430 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.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    Hi,

    I have a grid layout of 2x2
    aligned to QVBoxLayout.

    This code is in constructor.

    int col = 0;
    int row = 0;
    int m_layout  = 4
    int lay_col= 1;
    
    for(int i = 0 ; i < m_layout ; i++ )
    {
       m_List[i].m_label = new QLabel;
       m_List[i].m_label ->setText("Label");
    
       m_List[i].widget = new QWidget;
       m_List[i].widget->setStyleSheet("background-color:blue");
     
       m_grid->addWidget(m_List[i].m_label,row,col);
       m_grid->addWidget(m_List[i].widget,row,col);
    
    
       col++;
    
    
       if(col == lay_col)
       {
           row++;
           col = 0;
       }
    }
    m_vbox->addLayout(m_grid);
    setLayout(m_vbox)
    

    From the function when i need to change the gridlayout to the corresponding values provided from the function.
    for example 2x3 or so .

    How can i do it, guidance is required.

    Thanks,

    Pradeep Kumar
    Qt,QML Developer

    kshegunovK 1 Reply Last reply
    0
    • Pradeep KumarP Pradeep Kumar

      Hi,

      I have a grid layout of 2x2
      aligned to QVBoxLayout.

      This code is in constructor.

      int col = 0;
      int row = 0;
      int m_layout  = 4
      int lay_col= 1;
      
      for(int i = 0 ; i < m_layout ; i++ )
      {
         m_List[i].m_label = new QLabel;
         m_List[i].m_label ->setText("Label");
      
         m_List[i].widget = new QWidget;
         m_List[i].widget->setStyleSheet("background-color:blue");
       
         m_grid->addWidget(m_List[i].m_label,row,col);
         m_grid->addWidget(m_List[i].widget,row,col);
      
      
         col++;
      
      
         if(col == lay_col)
         {
             row++;
             col = 0;
         }
      }
      m_vbox->addLayout(m_grid);
      setLayout(m_vbox)
      

      From the function when i need to change the gridlayout to the corresponding values provided from the function.
      for example 2x3 or so .

      How can i do it, guidance is required.

      Thanks,

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      Something along those lines:

      qint32 columns = 5; // Or whatever comes as an argument
      QList<QWidget *> itemsToInsert;
      QGridLayout * layout;
      
      for (qint32 i = 0, size = itemsToInsert.size(); i < size; i++)
          layout->addWidget(itemsToInsert[i], i / columns, i % columns);
      

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      3

      • Login

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