Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, April 2008
Model/View programming: Getting the view index given the model index


Message 1 in thread

In general terms I'm looking for a way to obtain the the row/column 
indices's of a view given the QModelIndex of the associated model.

More specifically I'm looking for a way to move a column in a QTreeView 
given the column name in the QSqlTableModel.

I can almost do it like this:

m_pTreeView->header()->moveSection(m_pTreeModel->fieldIndex("first_name"), 
1);

Except if other columns (or this column) in the view have already been 
moved (either programmatically or by the user) then 
m_pTreeModel->fieldIndex("first_name") won't necessarily get you the 
index you want.

Does anyone have any ideas?

-Jason

--
 [ signature omitted ] 

Message 2 in thread

Jason Dolan a écrit :
> In general terms I'm looking for a way to obtain the the row/column 
> indices's of a view given the QModelIndex of the associated model.
> 
> More specifically I'm looking for a way to move a column in a QTreeView 
> given the column name in the QSqlTableModel.
> 
> I can almost do it like this:
> 
> m_pTreeView->header()->moveSection(m_pTreeModel->fieldIndex("first_name"), 
> 1);
> 
> Except if other columns (or this column) in the view have already been 
> moved (either programmatically or by the user) then 
> m_pTreeModel->fieldIndex("first_name") won't necessarily get you the 
> index you want.
> 
> Does anyone have any ideas?
> 
> -Jason

You should have a look at mapFromSource an mapToSource of 
QAbstractProxyModel, it will give you exactly what you are looking for.

You will have to insert a QProxyModel between your view and model if I 
remember correctly.

Passing QModelIndex to qDebug(), gives very usefull informations, colum, 
row, ... and to what the index is associated (Model ...)

Hope that's help

Nicolas

--
 [ signature omitted ]