[Qt-interest] Hide deleted rows in QSqlTableModel

Sean Harmer sean.harmer at maps-technology.com
Sat Nov 28 17:12:55 CET 2009


Hi,

Petric Frank wrote:
> Hello,
> 
> On Saturday 28 November 2009 10:17:15 Thomas Richard wrote:
>> I noticed that when using a QTreeView with a QSqlTableModel and using the
>> OnManualSubmit method there's no way to (visually) see if a certain row is
>> deleted. I found out this seems to be normal behavior as a QTableView would
>> show a '!' in front of the deleted row.
> 
> If you hide the vertical bar you don't even get the exclamation mark.
> 
>> In the application I'm writing there is a cancel button though which
>>  assures that changes aren't saved. Now the problem is that i would like to
>>  hide deleted rows from the QTreeView so the user can see that the row will
>>  be deleted. This obviously has to happen without a submitAll() call. I
>>  found a way to paint the background of a deleted row red but I still think
>>  that's not sufficient. Is there an easy way to hide the deleted rows?
> 
> The only way i found so far is to connect an own slot to
>   <table model>->headerDataChanged (...)
> 
> Inside this method i code the following:
> ---------------- cut --------------------
> void Class::OwnHeaderChanged (Qt::Orientation orientation, int start, int end)
> {
>    if (orientation != Qt::Vertical)
>     return;
> 
>   for (int loop = start; loop <= end; ++loop)
>   {
>     QVariant sign = <table model>->headerData (loop, orientation);
>     if (sign == QLatin1String ("!"))
>       ui.<table view>->hideRow (loop);
>   }
> }
> ---------------- cut --------------------
> 
> Hope that helps.
> 
> regards
>   Petric
> 
> P.S.: If you have a better solution - post it.

I would guess (but have not tried) that this could be achieved with a 
fairly simple subclass of QSortFilterProxyModel that sits between your 
QSqlTableModel and the view. Just do your check in the 
filterAcceptsRow() virtual function.

Cheers,

Sean



More information about the Qt-interest-old mailing list