PyQt5 QTreeWidget output to multiple columns -
i connect .ui file .py script
class mainwindow(qmainwindow): def __init__(self, *args): super(mainwindow, self).__init__(*args) loadui('ui.ui', self)
now can access qtreewidget, named treewidget1:
self.treewidget1
how can output multiple columns separately filename , extension?
i find example, here output fist column:
in self.fileslist1: if i.lower().endswith(tuple(ext_pattern)) , os.path.isfile(os.path.join(self.folder1, i)): row = os.path.splitext(i) self.treewidget1.inserttoplevelitems(0, [qtreewidgetitem(self.treewidget1, ["%s" % i])])
to add multiple columns each row, use:
self.treewidget1.inserttoplevelitems(0, [qtreewidgetitem(self.treewidget1, ["col1", "col2", "col3"])
replace "col1"
etc. appropriate strings derived filename.
note: using inserttoplevelitems(0, ...)
insert each item sequentially @ top of tree. might want consider using:
self.treewidget1.addtoplevelitem([qtreewidgetitem(self.treewidget1, ["col1", "col2", "col3"])
instead preserve order of self.fileslist1
.
Comments
Post a Comment