[Qt-jambi-interest] Problem for displaying header and data

Gunnar Sletta gunnar at trolltech.com
Mon Feb 2 13:06:31 CET 2009


Vincent Lebreil wrote:
> Hi,
> 
> I don't understand why nothing is displaying (neither header and data) 
> if I'm using a QTreeView and my own model which inherits QAbstractItemModel.
> 
> Btw if I use a QStandardItemModel instead, it works fine. Don't 
> understand why ??
> 
> Best Regards,
> Vincent

Hi Vincent,

Both the headerData() and data() functions are used to query the model 
for a number of different roles, such as font, color, text, etc. In your 
  example, you do not properly distinguish between roles and you 
probably end up with an invalid font and an invalid color. If you add a

if (role == Qt.ItemDataRole.DisplayRole)
{
     // look up string and return it
}
else return null;

around your data accessor functions, you should get the proper results.

-
best regards,
Gunnar



More information about the Qt-jambi-interest mailing list