Я пытаюсь показать пользовательские виджеты в области прокрутки, но он показывает только последний.
Содержимое области прокрутки должно динамически меняться с индексом поля со списком, и они изменяются и показывают последний элементтоже.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
fileMenu = ui->menuBar->addMenu(tr("&Archivo"));
openFileAction = new QAction(tr("Abir archivo"), this);
connect(openFileAction,
SIGNAL(triggered()),
this,
SLOT(openFile()));
fileMenu->addAction(openFileAction);
scroll = ui-> scrollArea;
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scroll->setWidgetResizable(true);
ui->stackedWidget->setCurrentIndex(0);
}
vector<product> MainWindow::filter(QString cad)
{
vector <product> tempList;
QMessageBox message;
for(size_t i(0);i<products.size();i++){
if(products.at(i).getId().contains(cad)){
product *p = new product;
p->setId(products.at(i).getId());
p->setName(products.at(i).getName());
p->setPrice(products.at(i).getPrice());
tempList.push_back(*p);
}
}
return tempList;
}
void MainWindow::loadproducts(int category){
QMessageBox message;
vector <product> tempList;
switch(category){
case Alimentos:{
tempList=filter("AB");
break;
}
case Libros:{
tempList=filter("L");
break;
}
case Electronicos:{
tempList=filter("E");
break;
}
case Hogar:{
tempList=filter("HC");
break;
}
case Deporte:{
tempList=filter("D");
break;
}
case Todos:{
tempList=products;
break;
}
default:{
break;
}
}
//THIS FOR IS SUPPOSED TO ADD WIDGETS TO SCROLL AREA
for(size_t i=0;i<tempList.size();i++){
ProductWidget *p = new ProductWidget(widget, tempList.at(i).getId(), tempList.at(i).getName(), tempList.at(i).getPrice());
scroll->setWidget(p);
}
tempList.clear();
}
В области прокрутки должно отображаться 10 виджетов, но отображается только последний.