Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. how to edit the Qlistwidget item on the contextmenu
Forum Updated to NodeBB v4.3 + New Features

how to edit the Qlistwidget item on the contextmenu

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
2 Posts 2 Posters 405 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.
  • T Offline
    T Offline
    Triomphe
    wrote on last edited by
    #1

    I want to make three action in the listwidget contextmenu.
    when I right click on the action that is named "rename"

            #右键菜单
            self.leftWidget.setContextMenuPolicy(Qt.CustomContextMenu)
            self.leftWidget.customContextMenuRequested.connect(self.myListWidgetContext)
    
        def myListWidgetContext(self,position):
            #弹出菜单
            popMenu = QMenu()
            creAct =QAction("新建分组",self)
            delAct =QAction("删除分组",self)
            renameAct =QAction(u'重命名', self)
            #查看右键时是否在item上面,如果不在.就不显示删除和修改.
            popMenu.addAction(creAct)
            if self.leftWidget.itemAt(position):
                popMenu.addAction(delAct)
                popMenu.addAction(renameAct)
    
            creAct.triggered.connect(self.CreateNewItem)
            renameAct.triggered.connect(self.RenameItem)
            delAct.triggered.connect(self.DeleteItem)
            popMenu.exec_(self.leftWidget.mapToGlobal(position))
    
        #创建新的分组
        def CreateNewItem(self):
            test =QListWidgetItem("test")
            test.setTextAlignment(Qt.AlignCenter)
            self.leftWidget.addItem(test)
    
    
        #删除分组
        def DeleteItem(self):
            self.leftWidget.takeItem(self.leftWidget.currentRow())
    
        #重命名分组
        def RenameItem(self):
            curRow =self.leftWidget.currentRow()
            item=self.leftWidget.item(curRow)
    
            item.setFlags(item.flags() | Qt.ItemIsEditable)
            self.leftWidget.openPersistentEditor(item)
    
    
    jsulmJ 1 Reply Last reply
    0
    • T Triomphe

      I want to make three action in the listwidget contextmenu.
      when I right click on the action that is named "rename"

              #右键菜单
              self.leftWidget.setContextMenuPolicy(Qt.CustomContextMenu)
              self.leftWidget.customContextMenuRequested.connect(self.myListWidgetContext)
      
          def myListWidgetContext(self,position):
              #弹出菜单
              popMenu = QMenu()
              creAct =QAction("新建分组",self)
              delAct =QAction("删除分组",self)
              renameAct =QAction(u'重命名', self)
              #查看右键时是否在item上面,如果不在.就不显示删除和修改.
              popMenu.addAction(creAct)
              if self.leftWidget.itemAt(position):
                  popMenu.addAction(delAct)
                  popMenu.addAction(renameAct)
      
              creAct.triggered.connect(self.CreateNewItem)
              renameAct.triggered.connect(self.RenameItem)
              delAct.triggered.connect(self.DeleteItem)
              popMenu.exec_(self.leftWidget.mapToGlobal(position))
      
          #创建新的分组
          def CreateNewItem(self):
              test =QListWidgetItem("test")
              test.setTextAlignment(Qt.AlignCenter)
              self.leftWidget.addItem(test)
      
      
          #删除分组
          def DeleteItem(self):
              self.leftWidget.takeItem(self.leftWidget.currentRow())
      
          #重命名分组
          def RenameItem(self):
              curRow =self.leftWidget.currentRow()
              item=self.leftWidget.item(curRow)
      
              item.setFlags(item.flags() | Qt.ItemIsEditable)
              self.leftWidget.openPersistentEditor(item)
      
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Triomphe Please explain clearly what you want to do. In what way do you want to "edit the Qlistwidget item"?

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

      1 Reply Last reply
      1

      • Login

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