python - How to find the parent of item when clicked in empty space PyQt4 QTreeWidget -
didn't quite know how word here go,
this part of program displays folders found in directory , subdirectorys in qtreewidget (it loads them fine) ability create new folders no matter depth in tree. example have directory:
data\examples\folders\
and right click in empty space in qtreewidget below folders branch, want ability create folder below directory becomes:
data\examples\folder\untitled\
i have context menu working cannot understand how implement way place new folder item @ specific depth not know parent of area clicked
here code (only retentive parts):
self.treelist = qtgui.qtreewidget() self.treelist.setheaderlabels(["name"]) self.treelist.setcontextmenupolicy(qtcore.qt.customcontextmenu) self.treelist.customcontextmenurequested.connect(self.opencontextmenu)
and opencontextmenu function
def opencontextmenu(self,point): addfolder = qtgui.qaction(qtgui.qicon("data\\icons\\folder.png"), "&new folder", self) addfolder.triggered.connect(self.addfoldertolist) item = self.treelist.itemat(point) #current mouse pos cpos = qtgui.qcursor() #context menu contextmenu = qtgui.qmenu(self) #context menu actions contextmenu.addaction(self.addfolder) contextmenu.exec_(cpos.pos())
what want happen when addfolder action triggered folder created beneath parent of area clicked.
thank taking time read this!
Comments
Post a Comment