[Qt-interest] QListView ModelColumn

Philipp Schmidt philschmidt at gmx.net
Fri Dec 4 17:51:36 CET 2009


Hi,

as QTreeView is not exactly what i need i just skimmed through the docs and 
overrode the data() method with the following code:

QVariant Class::data ( const QModelIndex& idx, int role ) const {
	if (!idx.isValid()) {
		return QVariant();
	} if (idx.column() == 0 && role == Qt::DisplayRole) {
		return record(idx.row()).value("lastname").toString() + ", " + 
record(idx.row()).value("firstname").toString();
	}
	return QSqlTableModel::data ( idx, role );
}

That works like a charm and wasn't really that hard to do :D. Thanks for your 
help anyway.

Philipp Schmidt


David Boosalis <david.boosalis at gmail.com> schrieb am Freitag, 04 Dezember 2009 
um 16:37:02:
> I do no think QListView can handle this, but strangely enough QTreeView
> can.  Just make sure to set decoration off.  The only major draw back to
> QTreeView is that you cannot get grid lines to show up (someone correct me
> if I am wrong).  You can set alternating colors for rows though and still
> sort by any column
> 
> On Fri, Dec 4, 2009 at 5:54 AM, Philipp Schmidt <philschmidt at gmx.net> wrote:
> > Hi,
> >
> > i was wondering if it is possible to get QListView to show more than one
> > column from a QSqlTableModel. In my case i would like it to show first-
> > and lastname together. (second and third column). If that is not possible
> > in the
> > default implementation, how would i need to proceed? My guess would be to
> > overwrite the data() function in the Model.
> >
> > Kind Regards
> > Philipp Schmidt
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> 



More information about the Qt-interest-old mailing list