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. Creating a 32x32 "Matrix" of dynamicaly added buttons into a layout!

Creating a 32x32 "Matrix" of dynamicaly added buttons into a layout!

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 349 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.
  • K Offline
    K Offline
    Kris Revi
    wrote on last edited by
    #1

    what am i doing wrong here? it only creates 1 button :S

        const int colCount = 32;
        const int rowCount = 32;
        int Index = 1;
        for (int r = 0; r < rowCount; r++) {
            for(int c = 0; c < colCount; c++) {
            QPushButton *button = new QPushButton(this);
    
            connect(button, &QPushButton::clicked, [=]() { qDebug() << button->objectName(); });
    
            button->setMinimumSize(16, 16);
            button->setMaximumSize(16, 16);
            button->setFixedSize(16, 16);
            button->setCursor(Qt::PointingHandCursor);
            button->setObjectName(QString::number(Index));
    
            ui->GRID_IMAGEFOLDER_DISPLAY->setColumnStretch(11, 100);
            //ui->GRID_IMAGEFOLDER_DISPLAY->setRowStretch(11, 100);
            ui->GRID_IMAGEFOLDER_DISPLAY->addWidget(button, rowCount, colCount);
    
            ++Index;
            }
        }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      No it does not create only one button, you set all your buttons in the same cell of your grid.

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

      K 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        No it does not create only one button, you set all your buttons in the same cell of your grid.

        K Offline
        K Offline
        Kris Revi
        wrote on last edited by
        #3

        @SGaist i see that now xD ...

        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