Hello everyone I have a problem using table view. I have a tableview connected with a QSqlTableModel. On its 2nd column I want to have check state to control the row's Status (active/inactive) but when I try to push the check box QTableView scrolls to the bottom and returns to it's previous position. Is there any solution?
{
if(index.column() == STATUS_INDEX) {
qrstr = (rec.field(index.column()).value().toInt() == 1) ? "update " + tableName() + " set Status=0 where BRACE_ID=" : "update " + tableName() + " set Status=1 where BRACE_ID=";
qrstr
+= QString().
setNum(index.
row()+1);
braceDatabase->exec(qrstr.toUtf8().constData());
return true;
}
return false;
}
void DataBase::updateTablesSlot()
{
if(projectsModel)
projectsModel->select();
if(attributesModel)
attributesModel->select();
if(targetsModel)
targetsModel->select();
}
void DataBase::exec(const std::string &querystr)
{
qr.exec(querystr.c_str());
//qDebug() <<"Command :" << querystr.c_str() << "-> "<< query->lastError().text();
updateTables();
}
bool ProjectsModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if(index.column() == STATUS_INDEX) {
QSqlRecord rec = this->record(index.row());
QString qrstr;
qrstr = (rec.field(index.column()).value().toInt() == 1) ? "update " + tableName() + " set Status=0 where BRACE_ID=" : "update " + tableName() + " set Status=1 where BRACE_ID=";
qrstr += QString().setNum(index.row()+1);
braceDatabase->exec(qrstr.toUtf8().constData());
return true;
}
return false;
}
void DataBase::updateTablesSlot()
{
if(projectsModel)
projectsModel->select();
if(attributesModel)
attributesModel->select();
if(targetsModel)
targetsModel->select();
}
void DataBase::exec(const std::string &querystr)
{
QSqlQuery qr(db);
qr.exec(querystr.c_str());
//qDebug() <<"Command :" << querystr.c_str() << "-> "<< query->lastError().text();
updateTables();
}
To copy to clipboard, switch view to plain text mode
35b599e7-599d-482b-af36-b69bf3062b02.jpg
Bookmarks