Add Context Menu to the people view
Fixes: #1 added contextMenuEvent handler. Make sure that we only present the menu when the cursor is over a name.
This commit is contained in:
17
main.py
17
main.py
@@ -20,7 +20,8 @@ from PyQt6.QtCore import (
|
||||
pyqtSlot,
|
||||
)
|
||||
from PyQt6.QtSql import QSqlDatabase, QSqlQuery, QSqlQueryModel
|
||||
from PyQt6.QtWidgets import QApplication, QFileDialog, QMainWindow
|
||||
from PyQt6.QtWidgets import QApplication, QFileDialog, QMainWindow, QMenu
|
||||
from PyQt6.QtGui import QContextMenuEvent
|
||||
|
||||
from lib import Book, PersonDialog, ReadDialog, SessionDialog, query_error
|
||||
from lib.preferences import Preferences
|
||||
@@ -59,6 +60,20 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.show()
|
||||
return
|
||||
|
||||
def contextMenuEvent(self, event: QContextMenuEvent) -> None:
|
||||
localPos = self.peopleView.mapFromGlobal(event.globalPos())
|
||||
if not self.peopleView.rect().contains(localPos):
|
||||
return
|
||||
index = self.peopleView.indexAt(localPos)
|
||||
if index.row() < 0:
|
||||
return
|
||||
menu = QMenu(self)
|
||||
menu.addAction(self.actionRead)
|
||||
self.actionEditPerson.setEnabled(True)
|
||||
menu.addAction(self.actionEditPerson)
|
||||
menu.exec(event.globalPos())
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def editPreferences(self) -> None:
|
||||
dlg = Preferences()
|
||||
|
||||
Reference in New Issue
Block a user