create the signal / slot for the QListWidget like this..
Assuming the QListWidget is called lbUserList...
connect(lbUserList,
SIGNAL(customContextMenuRequested
(const QPoint &)),
this,
SLOT(userListMenuRequested
(const QPoint &)));
connect(lbUserList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(userListMenuRequested(const QPoint &)));
To copy to clipboard, switch view to plain text mode
Then in the slot place some code like this
void MainWindowImpl
::userListMenuRequested(const QPoint & pos
) {
QPoint globalPos
= lbUserList
->mapToGlobal
(pos
);
// Map the global position to the userlist lbUserList->item(t.row())->setSelected(true); // even a right click will select the item
userListMenu->exec(globalPos);
}
void MainWindowImpl::userListMenuRequested(const QPoint & pos)
{
QPoint globalPos = lbUserList->mapToGlobal(pos); // Map the global position to the userlist
QModelIndex t = lbUserList->indexAt(pos);
lbUserList->item(t.row())->setSelected(true); // even a right click will select the item
userListMenu->exec(globalPos);
}
To copy to clipboard, switch view to plain text mode
Bookmarks