Getting a table cell content through a proxy from a model
-
I have an qtableview with a model and a proxy (QSortFilterProxyModel).
I know that when I'd like to get a specific cell content I need a modelindex from the proxy (and from the model).
What I want:
when the user clicks on a row on the table, he get a cell content from the selected row (from the 0. column).How can I solve this? Can sy send me a code snippet?
-
You can take a look at this example "https://gitorious.org/qt-training/course-material/trees/c71ad30d0b7271b70af39c5aa47d5bd6ad77005c/addon/modelview/ex-sortfiltertableview":https://gitorious.org/qt-training/course-material/trees/c71ad30d0b7271b70af39c5aa47d5bd6ad77005c/addon/modelview/ex-sortfiltertableviewhttp://
you can retrieve from QTableView clicked(QModelIndex) signal, an use the model index to get the information you need.
in SortedTableView I have done the next changes:
- create a new slot void clicked(const QModelIndex &index);
- made the connection, when clicked is performed to call the update method
@connect(_tableView, SIGNAL(clicked(QModelIndex)), SLOT(clicked(QModelIndex)));@
@#include <QtGui>
#include "SortedTableView.h"
SortedTableView::SortedTableView( QWidget *parent )
: QWidget ( parent )
, _filter ( new QSortFilterProxyModel() )
{
...
connect(_tableView, SIGNAL(clicked(QModelIndex)), SLOT(clicked(QModelIndex)));
...
}void SortedTableView::clicked(const QModelIndex &index)
{
QVariant v = index.data();
//just as a test, set the line filter with the value retrieved
_lineEdit->setText(v.toString());
}
@