I try created my own model for add checkbox in first column tableview.
#ifndef MODELANGGOTA_H
#define MODELANGGOTA_H
#include <QSqlQueryModel>
{
Q_OBJECT
public:
};
#endif // MODELANGGOTA_H
#ifndef MODELANGGOTA_H
#define MODELANGGOTA_H
#include <QSqlQueryModel>
class modelAnggota : public QSqlQueryModel
{
Q_OBJECT
public:
modelAnggota(QObject *parent = 0);
QVariant data(const QModelIndex &item, int role) const;
};
#endif // MODELANGGOTA_H
To copy to clipboard, switch view to plain text mode
#include "modelanggota.h"
modelAnggota
::modelAnggota(QObject *parent
){
}
{
if (role == Qt::CheckStateRole && index.column() == 0)
return Qt::Unchecked;
}
#include "modelanggota.h"
modelAnggota::modelAnggota(QObject *parent)
: QSqlQueryModel(parent)
{
}
QVariant modelAnggota::data(const QModelIndex &index, int role) const
{
if (role == Qt::CheckStateRole && index.column() == 0)
return Qt::Unchecked;
return QSqlQueryModel::data(index, role);
}
To copy to clipboard, switch view to plain text mode
model->setQuery("select * from mailbox");
ui->tableView->setModel( model );
ui->tableView->setAlternatingRowColors(TRUE);
QSqlQueryModel *model = new modelAnggota();
model->setQuery("select * from mailbox");
ui->tableView->setModel( model );
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setAlternatingRowColors(TRUE);
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
To copy to clipboard, switch view to plain text mode
But checkbox can't checked or unchecked. I need the checkbox not for edited data on table (database), but just for checked. Then, if I Click a pushButton (delete button), row with checked will remove. And yes, row in database table will removed too.
Have any suggestion ?
Sorry. my english is bad
Bookmarks