How to create a custom context menu which opens up when i right click in my QListWidget box named "syslist".
Unsolved
General and Desktop
-
i am new to this and have read the documentation provided by QT for context menu
i have this in my mainwindow.cppvoid MainWindow::contextMenuEvent(QContextMenuEvent *event) { QMenu menu(this); menu.addAction("cut Act"); menu.addAction("copy Act"); menu.addAction("paste Act"); menu.exec(event->globalPos()); }``` and this in my mainwindow.h protected: #ifndef QT_NO_CONTEXTMENU void contextMenuEvent(QContextMenuEvent *event) override; #endif // QT_NO_CONTEXTMENU ------------------------- but this opens the context menu when i right click anywhere in the window ??
-
Hi,
If you only want that menu for your QListWidget, then subclass that class rather than your MainWindow class.
-
Yes, but in a subclass.
You currently have MainWindow which is likely a subclass of QMainWindow. Apply the same concept to QListWidget.