[Qt-interest] Hide deleted rows in QSqlTableModel
Thomas Richard
thomas9999 at gmail.com
Sat Nov 28 19:51:50 CET 2009
Hey,
This is what I came up with. I think it does it's job good enough for me. This
treeview hides a row when delete is clicked and you didn't call submitAll()
yet. It unhides the row when you would call revertAll().
ImpTreeView.h
class ImpTreeView : public QTreeView
{
Q_OBJECT
public:
ImpTreeView(QWidget *parent = 0);
void setModel ( QAbstractItemModel * model );
private slots:
void headerDataChanged(Qt::Orientation orientation, int first, int last);
};
ImpTreeView.cpp
ImpTreeView::ImpTreeView(QWidget *parent ) : QTreeView(parent) {}
void ImpTreeView::setModel ( QAbstractItemModel * model )
{
connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), this,
SLOT(headerDataChanged(Qt::Orientation,int,int)));
QTreeView::setModel(model);
}
void ImpTreeView::headerDataChanged(Qt::Orientation orientation, int first,
int last)
{
if(orientation == Qt::Vertical)
{
for(int i = first; i <= last; ++i)
{
QVariant sign = model()->headerData(i, orientation);
if (sign == QLatin1String ("!"))
setRowHidden(i, QModelIndex(), true);
}
}
}
I hope this is useful for someone else too ;)
Greetings
Thomas
More information about the Qt-interest-old
mailing list