nategoofs
18th August 2007, 09:45
Im having some trouble with the QAbstractItemModel's remove row function working with a QTableView re-implementation. I call the function with the index from a contextMenuEvent and delete it accordingly:
void WTrackTableView :: contextMenuEvent(QContextMenuEvent * event)
{
index = indexAt(event->pos());
m_pTrackInfoObject = m_pTable->m_pTrackCollection->getTrack(index.row()+1);
if(index.isValid())
{
QMenu menu(this);
menu.addAction(PlayQueueAct);
menu.addAction(Player1Act);
menu.addAction(Player2Act);
menu.addAction(RemoveAct);
menu.exec(event->globalPos());
}
}
void WTrackTableView :: slotRemoveFromPlaylist()
{
qDebug("%i",index.row());
m_pTable->removeRow(index.row(),index);
}
index is a QModelIndex created in the header file so I can use it across functions. now, my problem is that if I select an item anywhere in the view the item still stays in the table but the item at the end of the table is removed. why would this be happening? The qDebug that I have returns the correct reference to the row that is selected, but nothing happens at that index.
void WTrackTableView :: contextMenuEvent(QContextMenuEvent * event)
{
index = indexAt(event->pos());
m_pTrackInfoObject = m_pTable->m_pTrackCollection->getTrack(index.row()+1);
if(index.isValid())
{
QMenu menu(this);
menu.addAction(PlayQueueAct);
menu.addAction(Player1Act);
menu.addAction(Player2Act);
menu.addAction(RemoveAct);
menu.exec(event->globalPos());
}
}
void WTrackTableView :: slotRemoveFromPlaylist()
{
qDebug("%i",index.row());
m_pTable->removeRow(index.row(),index);
}
index is a QModelIndex created in the header file so I can use it across functions. now, my problem is that if I select an item anywhere in the view the item still stays in the table but the item at the end of the table is removed. why would this be happening? The qDebug that I have returns the correct reference to the row that is selected, but nothing happens at that index.