Delete item from bookmark
Unsolved
QtWebEngine
-
I've created a toolbar with favourites pages, everything is going fine, but i don't know how to delete any item of it, it must to catch the right click of the mouse, show a contextMenu with a delete item and when you click the delete item it should delete the bookmark widget, it would looks like below:
Here's my code to create the bookmark toolbar
class BookMarkToolBar(QtWidgets.QToolBar): bookmarkClicked = QtCore.pyqtSignal(QtCore.QUrl, str) def __init__(self, parent=None): super(BookMarkToolBar, self).__init__(parent) self.actionTriggered.connect(self.onActionTriggered) self.bookmark_list = [] def setBoorkMarks(self, bookmarks): for bookmark in bookmarks: self.addBookMarkAction(bookmark["title"], bookmark["url"]) def addBookMarkAction(self, title, url): bookmark = {"title": title, "url": url} fm = QtGui.QFontMetrics(self.font()) if bookmark not in self.bookmark_list: text = fm.elidedText(title, QtCore.Qt.ElideRight, 150) action = self.addAction(text) action.setData(bookmark) self.bookmark_list.append(bookmark) @QtCore.pyqtSlot(QtWidgets.QAction) def onActionTriggered(self, action): bookmark = action.data() self.bookmarkClicked.emit(bookmark["url"], bookmark["title"]) self.bookmarkToolbar = BookMarkToolBar("Barra de marcadores") self.bookmarkToolbar.bookmarkClicked.connect(self.add_new_tab) self.addToolBar(self.bookmarkToolbar)
-
@GDPpy You can override https://doc.qt.io/qt-5/qwidget.html#mousePressEvent where you then get the action under cursor using https://doc.qt.io/qt-5/qtoolbar.html#actionAt