Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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;
            }
        }
    

  • Lifetime Qt Champion

    Hi,

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



  • @SGaist i see that now xD ...


Log in to reply