[Qt-interest] Hide deleted rows in QSqlTableModel

Petric Frank pfrank at gmx.de
Sat Nov 28 17:03:23 CET 2009


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.



More information about the Qt-interest-old mailing list