Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14215

Find and select element in QTreewidget in PyQT6

$
0
0

How to select this element in Qtreewidget using the path to an element?

The path is written as an example string: parent/parent/parent/parent/element

It is important to search for elements along the entire path and not only by the name of this element, because there may be many elements in the tree with the same name, but each one will certainly have a different path.

I tried to solve it in ten ways:

def find_and_select_item(self):    path = self.comboBox_Scene.currentText()    path_elements = path.split('/')    current_item = self.treeWidget.invisibleRootItem()    for element in path_elements:        items = self.treeWidget.findItems(element, Qt.MatchFlag, 0)        if items:            current_item = items[0]        else:            # Element not found in the current level of the tree            return None    # Select the found item    current_item.setSelected(True)    return current_item

Unfortunately, this function returns an error::
TypeError: findItems(self, text: str, flags: Qt.MatchFlag, column: int = 0): argument 2 has unexpected type 'EnumType'


Viewing all articles
Browse latest Browse all 14215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>