PDA

View Full Version : QSpinbox and mapper



marsqtc789
15th June 2015, 14:31
Hello world, i'm on a problem since 3 days. i have a qtableView and some qlineEdits and qspinbox linked by a qdatawidgetmapper. if i select a row in the model it automatically change the spinbox and the lineEdits. now i want to make the selection on the model in the view change when the qspinbox's value change. thanks in advance...!

d_stranz
17th June 2015, 04:48
So connect a slot to the spin box's valueChanged() signal, and use that with QItemSelectionModel::select(), converting the spin box value into a QModelIndex row value:



void MyWidget::onValueChanged( int value )
{
QItemSelectionModel * pSelModel = myTableView->getSelectionModel();

QAbstractItemModel * pModel = pSelModel->model();
QModelIndex selIndex = pModel->index( value, 0 );
pSelModel->select( selIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Columns );
}