QTableView item selected signal?
Hi Folks...
I'm having an issue figuring out what signals are emitted by a QTableView when the user performs various actions for selecting a row (my table is configured for row selection mode, single selection)...
I'm connecting to the clicked() signal and can pick up on row selection when the user clicks on a row - all fine and well. However, if the user then uses the up/down arrow keys to select new rows, the clicked() signal is not emitted - as I suppose would be expected.
Why is it that there just doesn't seem to be a signal letting us know that the set of selected items has changed? Am I just overlooking this somewhere in the docs?
Thanks!
Btw, I'm using Qt 4.6 on Windows
-G
Re: QTableView item selected signal?
Quote:
Originally Posted by
sherbs
Am I just overlooking this somewhere in the docs?
Yup, look at QAbstractItemView::selectionModel() and QItemSelectionModel.
Re: QTableView item selected signal?
Thanks... that helps a lot!
Re: QTableView item selected signal?
I finally got around to implementing this and ran into an unexpected issue:
QObject::connect: Cannot connect (null)::currentRowChanged(QModelIndex,QModelIndex) to MainWindow::on_tableViewTriggerSelectionModel_curr entRowChanged(QModelIndex,QModelIndex)
My code for doing the connection is as follows:
QItemSelectionModel *sm = ui->tableViewTrigger->selectionModel();
connect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)) ,
this, SLOT(on_tableViewTriggerSelectionModel_currentRowC hanged(QModelIndex,QModelIndex)));
Any idea why the selection model is coming back as null? I'm using QtCreator to design/build... in that I'm setting selectionMode to SingleSelection and selectionBehavior to SelectRows
Do I need to explicitly create the selection model?
Thanks for any help!
Re: QTableView item selected signal?
Quote:
Originally Posted by
sherbs
I guess you set the model after the code above. Try to set the model first.
Code:
ui->tableViewTrigger->setModel(yourModel);
Re: QTableView item selected signal?
Here is the order in which things are happening (simplified somewhat for clarity):
Code:
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
this->_initializeTables();
}
setupUi() is doing the following:
and my initialization routine for my tables does this:
Code:
void MainWindow::_initializeTables()
{
}
I was under the impression that setting the SelectionMode and SelectionBehavior would be something that manipulated a default sort of SelectionModel...
Apparently these two things are not the same and that a SelectionModel must be created by the programmer to do this? In a way, I find that kind of surprising since selecting items from a view of any sort is a common task.
Re: QTableView item selected signal?
You don't have to create a selection model by yourown. Qt does it as soon as you set a (data)model to the view. Qt does it at that time because if the view is empty no selection model is needed. As soon as it is needed it creates one with you specified mode and behavior.
Re: QTableView item selected signal?
Thanks much!
That was the problem...
I was setting the model for the table view *after* making that connection... Setting the model prior did the trick.
-G