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. Widgets in QGridlayout
Forum Updated to NodeBB v4.3 + New Features

Widgets in QGridlayout

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.8k Views 2 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.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    Hi,

    i am using QGridlayout to show QLabel and QWidget,

    in a loop

    
    int m_layout  = 4
    
    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);
    }
        m_vbox->addLayout(m_grid);
    

    but it is not coming one after the other in vertical fashion, it is overlaying, how to provide to make label and widget appear vertically in QGridLayout

    Thanks,

    Pradeep Kumar
    Qt,QML Developer

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Carmoneer
      wrote on last edited by
      #2

      You are not incrementing your 'row' and/or 'col' variable at the end of your loop.

      1 Reply Last reply
      0
      • Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by
        #3

        I am updating at the end of the loop, the problem is i want

           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");
        

        to be in vertical aligned in each cell of the grid.

        in the link below , only widget is appearing, i want to have label at the top of widget in each cell

        https://postimg.org/image/huzoyoxw7/

        Thanks,

        Pradeep Kumar
        Qt,QML Developer

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          There's no trace of changing the values of row nor col in your loop.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Pradeep KumarP Offline
            Pradeep KumarP Offline
            Pradeep Kumar
            wrote on last edited by
            #5

            Hi,

             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);
            

            Thanks,

            Pradeep Kumar
            Qt,QML Developer

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're adding both widgets to the same cell. If you want them both in the same cell then you have to put them in a layout and put that layout in the cell.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • Pradeep KumarP Offline
                Pradeep KumarP Offline
                Pradeep Kumar
                wrote on last edited by
                #7

                yup got it added both the widgets to vbox and then to gridlayout.

                Thanks,

                Pradeep Kumar
                Qt,QML Developer

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You're welcome !

                  Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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