qt tableview如何去除导航
2个回答
展开全部
QStandardItemModel *model = new QStandardItemModel();
ui->tableView->setModel(model);
.
.
.
int curRow = ui->tableView->currentIndex().row();
model->removeRow(curRow);
视图模型,model实现对数据的操作。
void XXX::DeleteITEM()
{
QItemSelectionModel *selectionModel = table_view->selectionModel();
if (selectionModel->hasSelection()) {
QModelIndexList indexList = selectionModel->selectedIndexes();
QModelIndex index = indexList.at(1); // 第几列
QString strTaskName = index.data().toString();
qDebug() << strTaskName;
} else {
QMessageBox::information(NULL, tr("Information"), tr("not select"));
}
}
void MainWindow::deleteItem()
{
QModelIndex index = treeView->selectionModel()->currentIndex();
treeModel->removeRow(index.row(), index.parent());
}
搞出来了,只是换了种方法
QSqlQuery query;
// query.prepare("delete from student where id = 2");
// query.bindValue(curRow);
int curRow = ui->tableView->currentIndex().row();
QModelIndex index = ui->tableView->currentIndex();
int id=index.sibling(curRow,0).data().toInt();
qDebug("shuzi is %d",id);
query.prepare("delete from information where id = :id");
query.bindValue(":id",id);
ui->tableView->setModel(model);
.
.
.
int curRow = ui->tableView->currentIndex().row();
model->removeRow(curRow);
视图模型,model实现对数据的操作。
void XXX::DeleteITEM()
{
QItemSelectionModel *selectionModel = table_view->selectionModel();
if (selectionModel->hasSelection()) {
QModelIndexList indexList = selectionModel->selectedIndexes();
QModelIndex index = indexList.at(1); // 第几列
QString strTaskName = index.data().toString();
qDebug() << strTaskName;
} else {
QMessageBox::information(NULL, tr("Information"), tr("not select"));
}
}
void MainWindow::deleteItem()
{
QModelIndex index = treeView->selectionModel()->currentIndex();
treeModel->removeRow(index.row(), index.parent());
}
搞出来了,只是换了种方法
QSqlQuery query;
// query.prepare("delete from student where id = 2");
// query.bindValue(curRow);
int curRow = ui->tableView->currentIndex().row();
QModelIndex index = ui->tableView->currentIndex();
int id=index.sibling(curRow,0).data().toInt();
qDebug("shuzi is %d",id);
query.prepare("delete from information where id = :id");
query.bindValue(":id",id);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询