I am using QListView to show list of friends' names. When I click on a name it should select a name and show profile related information and on right click it needs to show context menu without selecting a name and showing profile information. The problem I am facing is on right click it is selecting the name and also shows the context menu. I don't want the name to be selected on the right click and only the context menu should be shown. I am using the Qt contextmenuevent like:
void contextMenuEvent(QContextMenuEvent *ce)
{
QPoint pos = ce->pos();
emit customContextMenuRequested(pos);
}
This doesn't work and the above slot is never called.
use mousePressEvent and handle the right click like the following
void QkFriendsListView::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton)
{
emit customContextMenuRequested(event->pos());
}
else
QListView::mousePressEvent(event)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With