PDA

View Full Version : QTableView help



weaver4
24th November 2009, 18:07
I am using a QTableView to display a QSqlTableModel.


ui->tableView->setModel(myTableModel);
ui->tableView->show();


But when the user changes rows I want to get some information from the db and display it in a side widget. But in QTableView there is no signal that the row has been changed. I cannot use a QTableWiget because it will not "bind" to a QSqlTableModel...it says setModel() is private.

So QTableWidget will give a signal when a row has changed positions but it will not bind to the QSqlTableModel.

What is the best way to do this?

wysota
24th November 2009, 19:33
The signal is in the model - QAbstractItemModel::dataChanged().

weaver4
24th November 2009, 21:05
That does not work. The only time I could get that signal to "fire" was when the contents of a cell changed. I want to know when a new row is "selected".

Lykurg
24th November 2009, 21:24
I want to know when a new row is "selected".

QAbstractItemView::selectionModel() and QItemSelectionModel::currentRowChanged().

weaver4
24th November 2009, 22:57
I am new to this and I just don't understand how to set that up.

Here is what I have now. But everytime I select a new row it crashes.



MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{

ui->setupUi(this);

wrkTable = dbgmgr.OpenDB("moz_downloads","","downloads.sqlite");

if (wrkTable)
{
connect(wrkTable, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
this, SLOT(rowMoved(QModelIndex, QModelIndex)));

ui->tableView->setModel(wrkTable);
ui->tableView->show();
QItemSelectionModel sm(wrkTable);
ui->tableView->setSelectionModel(&sm);

dbgmgr.DebugInfo(true);
}
else
qDebug() << "Error: " << dbgmgr.error;
}

void MainWindow::rowMoved(QModelIndex tl,QModelIndex br)
{
qDebug() << "Row Moved! ";
}


I got it!

Thanks