The selection and the current cell are two different things and are highlighted different ways.
If you want to keep them in synchronisation then you could do it in the currentIndexChanged() slot of the view.
A complete example:
#include <QtGui>
#include <QDebug>
Q_OBJECT
public:
setSelectionMode(SingleSelection);
setSelectionBehavior(SelectRows);
}
protected slots:
selectRow(current.row());
}
};
int main(int argc, char *argv[])
{
// Some test data
for (int row = 0; row < 3; ++row) {
for (int col = 0; col < 2; ++col) {
model.setItem(row, col, item);
}
}
TableView t;
t.setModel(&model);
t.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
class TableView: public QTableView {
Q_OBJECT
public:
TableView(QWidget *p = 0): QTableView(p) {
setSelectionMode(SingleSelection);
setSelectionBehavior(SelectRows);
}
protected slots:
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
selectRow(current.row());
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Some test data
QStandardItemModel model(3,2);
for (int row = 0; row < 3; ++row) {
for (int col = 0; col < 2; ++col) {
QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(col));
model.setItem(row, col, item);
}
}
TableView t;
t.setModel(&model);
t.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks