Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeWidgetItem Text Edited Signal

QTreeWidgetItem Text Edited Signal

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.0k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    elveatles
    wrote on last edited by
    #1

    Hello,
    This is PyQt4, but is similar to C++.
    After doing a lot of research, it turns out that something as simple as getting a signal when editing the text on a QTreeWidgetItem is annoyingly difficult. There's the QTreeWidget.ItemChanged signal, but it fires for every little change that happens when all I wanted was to get a signal on text change. I was able to figure something out, but it seems kind of hacky. I was wondering if anyone here could share a more elegant way of solving this problem.

    @
    class SignalObject(QObject):
    Edited = pyqtSignal(QTreeWidgetItem)

    def __init__(self):
        super(SignalObject, self).__init__()
    

    class CustomTreeWidgetItem(QTreeWidgetItem):
    def init(self, parent=None):
    super(CustomTreeWidgetItem, self).init(parent)
    self.signalObject = SignalObject()

    def setData(self, column, role, value):
        super(FileTreeWidgetItem, self).setData(column, role, value)
    
        if role == Qt.EditRole:
            self.signalObject.Edited.emit(self)
    

    @

    First problem with this is QTreeWidgetItem doesn't inherit from QObject, so I had to create a custom class that inherits from QObject that stores all of my custom signals. Second problem is, I'm barely changing QTreeWidgetItem's functionality with my inherited class. I have to write all this code just to check if the role was Qt.EditRole.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Instead of using the QTreeWidget, you can try with QTreeView, SelectioModel and Delegate of QTreeView. Getting the existing delegate and observing some of the singnals from delegate may help you.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • E Offline
        E Offline
        elveatles
        wrote on last edited by
        #3

        Thanks, I'll look into this.

        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