From 52d1cfda8446577408104f8b10fabc3fa7b8c8f8 Mon Sep 17 00:00:00 2001 From: Flavio Date: Sat, 19 Jul 2014 00:29:54 +0200 Subject: [PATCH] Better context menu code, also working on Windows --- src/channelview.cpp | 11 +++++++---- src/channelview.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/channelview.cpp b/src/channelview.cpp index eef1a72..318f666 100644 --- a/src/channelview.cpp +++ b/src/channelview.cpp @@ -72,10 +72,6 @@ ChannelView::ChannelView(QWidget *parent) : QListView(parent), setMouseTracking(true); - setContextMenuPolicy(Qt::CustomContextMenu); - connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), - SLOT(showContextMenu(const QPoint &))); - connect(this, SIGNAL(clicked(const QModelIndex &)), SLOT(itemActivated(const QModelIndex &))); connect(this, SIGNAL(entered(const QModelIndex &)), @@ -186,6 +182,13 @@ void ChannelView::disappear() { MainWindow::instance()->showActionInStatusBar(action, false); } +void ChannelView::mousePressEvent(QMouseEvent *event) { + if (event->button() == Qt::RightButton) + showContextMenu(event->pos()); + else + QListView::mousePressEvent(event); +} + void ChannelView::mouseMoveEvent(QMouseEvent *event) { QListView::mouseMoveEvent(event); const QModelIndex index = indexAt(event->pos()); diff --git a/src/channelview.h b/src/channelview.h index 1a6fd5a..f8fa206 100644 --- a/src/channelview.h +++ b/src/channelview.h @@ -42,6 +42,7 @@ public slots: void disappear(); protected: + void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); void leaveEvent(QEvent *event); void paintEvent(QPaintEvent *event); -- 2.39.5