Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Delete item from bookmark

Delete item from bookmark

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 2 Posters 450 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GDPpy
    wrote on last edited by
    #1

    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:

    2ef2e150-84bd-416e-bb6c-2ab654da47ab-image.png

    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)
    
    jsulmJ 1 Reply Last reply
    0
    • G GDPpy

      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:

      2ef2e150-84bd-416e-bb6c-2ab654da47ab-image.png

      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)
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved