I am developing an application using Qt. Within the mainwindow.cpp file, I have a frame that displays another widget. This widget is populated with QPushButtons generated dynamically from the database. The maximum limit for buttons is set at 8. Here is the code snippet responsible for creating the buttons:
for(int i = 0; i < btnlst.count(); ++i)
{
QPushButton *b = new QPushButton(this);
b->setStyleSheet("background-color: qlineargradient(spread:pad, x1:1, y1:0.682, x2:1, y2:0, stop:0.142857 rgba(220, 0, 22, 255), stop:0.980296 rgba(216, 74, 73, 255), stop:1 rgba(217, 73, 73, 255)); border:none; color:white;");
b->setText(btnlst[i]);
if(mood=="Frame")
{
QSize size(55,55);
b->setMinimumSize(size);
b->setMaximumSize(size);
b->setSizePolicy(QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
ui->gridLayout->addWidget(b,0,i,Qt::AlignVCenter);
}
else
{
QSize size(70,70);
b->setMinimumSize(size);
b->setMaximumSize(size);
b->setSizePolicy(QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
if(i<4)
ui->gridLayout->addWidget(b,0,i,Qt::AlignVCenter);
else
ui->gridLayout->addWidget(b,0,i-3,Qt::AlignVCenter);
}
connect(b,SIGNAL(clicked()),this,SLOT(Function()));
btn << b;
}
ui->gridLayout->setSpacing(0);
To maintain consistency in appearance, I have set the widget's size to a maximum of 750x150 and a minimum of 600x150. Below are images illustrating my widget layout (utilizing vertical alignment) as well as the result displayed on an embedded device:
https://i.sstatic.net/0aFJu.jpg
https://i.sstatic.net/OCvLP.jpg
While the desired black color for the widget and white color for the group box are achieved, there are unwanted gaps between each button. Additionally, only 5 out of the 8 created buttons are visible within the frame. How can I reduce the spacing between buttons?