代码拉取完成,页面将自动刷新
#include "dishrecommendunit.h"
#include "ui_dishrecommendunit.h"
#include "dishitem.h"
#include <QToolButton>
#include <dishdetail.h>
DishRecommendUnit::DishRecommendUnit(QWidget *parent,QString title,QList<Dish>* dishList) :
QWidget(parent),
ui(new Ui::DishRecommendUnit),
title(title),
dishList(dishList)
{
ui->setupUi(this);
ui->lable_title->setText(ui->lable_title->text()+title);
for(int i = ui->stackedWidget->count(); i >= 0; i--)
{
QWidget* widget = ui->stackedWidget->widget(i);
ui->stackedWidget->removeWidget(widget);
widget->deleteLater();
}
for(int i=0;i<dishList->count();i++)
{
Dish aDish = dishList->at(i);
DishItem* dishItem = new DishItem(this,aDish.id,aDish.name,aDish.material,aDish.detail,aDish.pic,aDish.type);
ui->stackedWidget->insertWidget(i,dishItem);
}
int totalIndex = ui->stackedWidget->count();
// qDebug()<<totalIndex;
ui->stackedWidget->setCurrentIndex(0);
connect(ui->btn_after,&QToolButton::clicked,[=](){
int current = ui->stackedWidget->currentIndex();
current++;
if(current==totalIndex)
{
current = 0;
}
// qDebug()<<current;
ui->stackedWidget->setCurrentIndex(current);
});
connect(ui->btn_before,&QToolButton::clicked,[=](){
int current = ui->stackedWidget->currentIndex();
current--;
if(current==-1)
{
current = totalIndex-1;
}
// qDebug()<<current;
ui->stackedWidget->setCurrentIndex(current);
});
}
DishRecommendUnit::~DishRecommendUnit()
{
delete ui;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。