I have declared a QLabel array (which i will be using as picture boxes) and the function call which is going to fill the array in the header file of the project as:
void fillArray();
QLabel *label_array[7];
Then i called the declared function in the main(). That function is going to fill the array and add the labels to the QTabWidget tab's body. In the source file i wrote the following:
void MainWindow::fillArray()
{
for (int i = 0; i < sizeof(MainWindow::label_array) - 1; i++)
{
MainWindow::label_array[i] = new QLabel("Label " + i + 1);
ui->tabWgt->widget(0)->layout()->addWidget(MainWindow::label_array[i])
}
}
But the problem is it returns an error at the moment i build the program. I tried creating a layout and adding it to the layout and setting the tab's layout to that layout, it works, but it gets really messy and it is not understandable.
void MainWindow::fillArray()
{
QHBoxLayout *layout = new QHBoxLayout;
for (int i = 0; i < sizeof(MainWindow::label_array) - 1; i++)
{
MainWindow::label_array[i] = new QLabel("Label " + i + 1);
MainWindow::label_array[i]->move(10, 5*i); // this doesn't work...
layout->addWidget(MainWindow::label_array[i]);
}
ui->tabWgt->widget(0)->setLayout(layout);
}
Is it possible to add the labels directly to the tab's body without having to declare a layout (since i'd need to do it to every created array i declare along my program, and i have no idea how they are being located)?
How to position the label correctly?