Hi all,
Kinda figure someone would have already done/asked this ... I cannot find it if they have!
Learning and Tinkering with the Media Player Example.
My goal is learning the underlying PlaylistModel.
Trying to add the ability to remove items from the playlist, Added:
{
switch (event->key()) {
case Qt::Key_Delete:
if(playlistView->hasFocus())
removeFromPlaylist();
break;
default:
event->ignore();
break;
}
}
void Player::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Delete:
if(playlistView->hasFocus())
removeFromPlaylist();
break;
default:
event->ignore();
break;
}
}
To copy to clipboard, switch view to plain text mode
And
void Player::removeFromPlaylist()
{
if(!idx.isValid())
return;
playlist->removeMedia(idx.row());
}
void Player::removeFromPlaylist()
{
QModelIndex idx = playlistView->currentIndex();
if(!idx.isValid())
return;
playlist->removeMedia(idx.row());
}
To copy to clipboard, switch view to plain text mode
The item is removed however there are errors if within four items of the end of list.
The errors are:
QAbstractItemModel::endInsertRows: Invalid index
( 4 ,
0 ) in model PlaylistModel
(0x1a676848
)
QAbstractItemModel::endInsertRows: Invalid index ( 4 , 0 ) in model PlaylistModel(0x1a676848)
To copy to clipboard, switch view to plain text mode
Of course the numbers change ....
If the last item is always the item that is removed it works fine, It appears to be trying to select the row +3 after deletion and I cannot figure out why.
Any ideas/suggestions/fixes ???
-Enjoy
fh : )_~
Bookmarks