[Qt-interest] QListView ModelColumn
Philipp Schmidt
philschmidt at gmx.net
Mon Dec 7 10:46:24 CET 2009
I just needed a simple, non editable list to show the names of persons as
"lastname, firstname" to be able to select them and then edit them in a
separate widget. Since the data edited that way is stored in many tables a
table view was not the best solution in my opinion (Especially as it would
have only been used to select the records, which i believe is actually the
main reason for having a list). As said before: I got it working as i intended
it to :).
Philipp
qt-interest-request at trolltech.com schrieb am Montag, 07 Dezember 2009 um
10:06:53:
> Message: 3
> Date: Mon, 07 Dec 2009 09:42:24 +0100
> From: Andre Somers <andre at familiesomers.nl>
> Subject: Re: [Qt-interest] QListView ModelColumn
> To: Qt-interest <qt-interest at trolltech.com>
> Message-ID: <4B1CBFF0.4040202 at familiesomers.nl>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Philipp Schmidt wrote:
> > 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
>
> If you need multiple columns, why not use the view that was made for
> that: QTableView? I know it looks like an ugly spreadsheet in the
> default setup, but that's easy enough to change.
>
> Andr?
More information about the Qt-interest-old
mailing list