[Qt-interest] Hide deleted rows in QSqlTableModel
Thomas Richard
thomas9999 at gmail.com
Sat Nov 28 20:20:59 CET 2009
Err, unfortunately the changes do not get reverted. I thought they would
because i used some old testcode which made every row visibile again manually.
It seems like headerDataChanged isn't emitted when a deleted row gets
reverted. I think this is a bug though. Should i report it?
I can't seem to find a way to make revert work correctly then it seems. Too
bad.
Greetings
Thomas
On Saturday 28 November 2009 19:51:50 you wrote:
> 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