I made the move up and down functions and this is what my .cpp
contains
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
model = new QStandardItemModel(4,2,this);
for(int row = 0; row < 4; row++)
{
for(int col = 0; col < 2; col++)
{
QModelIndex index
= model->index(row,col,QModelIndex());
// 0 for all data
model->setData(index,row);
}
}
ui->tableView->setModel(model);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_upPushButton_clicked()
{
if(ui->tableView->currentIndex().row()<=0)
{
return;
}
QList<QStandardItem *> list = model->takeRow(ui->tableView->currentIndex().row());
model->insertRow(ui->tableView->currentIndex().row(),list);
}
void Widget::on_downPushButton_clicked()
{
int selectedRow = ui->tableView->currentIndex().row() ;
if(selectedRow == ui->tableView->model()->rowCount()-1)
{
return;
}
QList<QStandardItem *> list = model->takeRow(ui->tableView->currentIndex().row());
model->insertRow(selectedRow+1,list);
}
This is what the ui looks like