This code works fine
void Widget::on_moveRightButton_clicked()
{
QModelIndexList leftSelection = ui->leftView->selectionModel ()->selectedIndexes ();
int rowCount;
rowCount = m_rightModel.rowCount ();
m_rightModel.insertRow (rowCount);
m_rightModel.setData (m_rightModel.index (rowCount), idx.data ());
}
for (int i = leftSelection.size (); i > 0; --i) {
m_leftModel.removeRow (leftSelection.at (i - 1).row ());
}
}
void Widget::on_moveLeftButton_clicked()
{
QModelIndexList rightSelection = ui->rightView->selectionModel ()->selectedIndexes ();
int rowCount;
rowCount = m_leftModel.rowCount ();
m_leftModel.insertRow (rowCount);
m_leftModel.setData (m_leftModel.index (rowCount), idx.data ());
}
for (int i = rightSelection.size (); i > 0; --i) {
m_rightModel.removeRow (rightSelection.at (i - 1).row ());
}
}
void Widget::on_moveRightButton_clicked()
{
QModelIndexList leftSelection = ui->leftView->selectionModel ()->selectedIndexes ();
int rowCount;
Q_FOREACH (QModelIndex idx, leftSelection) {
rowCount = m_rightModel.rowCount ();
m_rightModel.insertRow (rowCount);
m_rightModel.setData (m_rightModel.index (rowCount), idx.data ());
}
for (int i = leftSelection.size (); i > 0; --i) {
m_leftModel.removeRow (leftSelection.at (i - 1).row ());
}
}
void Widget::on_moveLeftButton_clicked()
{
QModelIndexList rightSelection = ui->rightView->selectionModel ()->selectedIndexes ();
int rowCount;
Q_FOREACH (QModelIndex idx, rightSelection) {
rowCount = m_leftModel.rowCount ();
m_leftModel.insertRow (rowCount);
m_leftModel.setData (m_leftModel.index (rowCount), idx.data ());
}
for (int i = rightSelection.size (); i > 0; --i) {
m_rightModel.removeRow (rightSelection.at (i - 1).row ());
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks