First of all I suggest you stopped using the Q3Support library (Q3PopupMenu - why not use QMenu?).
I see you misunderstand the concept of actions and menus. I'd suggest something like this (this is not a complete code!):
class MyClass : public ... {
//...
private:
};
MyClass::MyClass() {
//...
m_addAction
= new QAction("Add to playlist",
this);
m_removeAction
= new QAction("Remove from playlist",
this);
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addToPlaylist()));
connect(m_removeAction, SIGNAL(triggered()), this, SLOT(removeFromPlaylist()));
//...
}
void MyClass
::playListMenu(QPoint &pt
){ if(shouldAddToPlaylist()){
menu.addAction(m_addAction);
} else {
menu.addAction(m_removeAction);
}
menu.exec(pt);
}
class MyClass : public ... {
//...
private:
QAction *m_addAction;
QAction *m_removeAction;
};
MyClass::MyClass() {
//...
m_addAction = new QAction("Add to playlist", this);
m_removeAction = new QAction("Remove from playlist", this);
connect(m_addAction, SIGNAL(triggered()), this, SLOT(addToPlaylist()));
connect(m_removeAction, SIGNAL(triggered()), this, SLOT(removeFromPlaylist()));
//...
}
void MyClass::playListMenu(QPoint &pt){
QMenu menu;
if(shouldAddToPlaylist()){
menu.addAction(m_addAction);
} else {
menu.addAction(m_removeAction);
}
menu.exec(pt);
}
To copy to clipboard, switch view to plain text mode
You can also add both actions and simply disable or hide the one you don't want. You'll get cleaner code then. Although for the QListView I'd use QWidget::customContextMenuRequested( const QPoint & pos ) signal and QAbstractItemView::indexAt() to fetch the item under cursor, but I don't know what you're exactly doing so some other approach might be better.
Bookmarks