From 097b32c70d157e1fa0c882037453e3513f1499dd Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Wed, 16 Jul 2025 00:43:01 +0800 Subject: [PATCH] UI: add context menu for later use --- mainwindow.cpp | 12 +++++++++++- mainwindow.h | 1 + mainwindow.ui | 19 +++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 73f1775..6e6027e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -267,6 +268,16 @@ void MainWindow::dropEvent(QDropEvent *e) } } +void MainWindow::contextMenuEvent(QContextMenuEvent *event) +{ + QMenu * menu = new QMenu; + menu->addAction(ui->actionHelp); + menu->exec(mapToGlobal(event->pos())); + menu->deleteLater(); + + return QMainWindow::contextMenuEvent(event); +} + void MainWindow::loadFile() { QStringList musicFolders(QStandardPaths::standardLocations(QStandardPaths::MusicLocation)); @@ -734,4 +745,3 @@ QGraphicsDropShadowEffect *MainWindow::createLabelShadowEffect() effect->setOffset(1, 1); return effect; } - diff --git a/mainwindow.h b/mainwindow.h index 1907c76..e60c494 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -55,6 +55,7 @@ protected: void mouseReleaseEvent(QMouseEvent *event) override; void dragEnterEvent(QDragEnterEvent *e) override; void dropEvent(QDropEvent *e) override; + void contextMenuEvent(QContextMenuEvent *event) override; void loadFile(); void loadFile(const QUrl &url); diff --git a/mainwindow.ui b/mainwindow.ui index db2032d..12c6926 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -217,7 +217,7 @@ QListView { - Qt::Orientation::Horizontal + Qt::Horizontal @@ -295,7 +295,7 @@ QListView { - QLayout::SizeConstraint::SetDefaultConstraint + QLayout::SetDefaultConstraint 10 @@ -364,7 +364,7 @@ QListView { 0:00 - Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -599,7 +599,7 @@ QListView { 100 - Qt::Orientation::Horizontal + Qt::Horizontal @@ -653,17 +653,20 @@ QListView { + + + - Help + About - Help + About F1 - QAction::MenuRole::NoRole + QAction::AboutRole @@ -677,7 +680,7 @@ QListView { Ctrl+O - QAction::MenuRole::NoRole + QAction::NoRole