Some changes to item classes, and added a sample context menu to the tree view

This commit is contained in:
Veronica K. B. Olsen
2019-04-13 21:45:55 +02:00
parent eca8a807ce
commit 4d448cad9d
4 changed files with 51 additions and 24 deletions
+36 -9
View File
@@ -16,7 +16,7 @@ import nw
from os import path
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QTreeWidgetItemIterator, QAbstractItemView
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QTreeWidgetItemIterator, QAbstractItemView, QMenu, QAction
from nw.enum import nwItemType, nwItemClass
@@ -42,6 +42,10 @@ class GuiDocTree(QTreeWidget):
if not self.debugGUI:
self.hideColumn(3)
# Context Menu
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self._openContextMenu)
# Allow Move by Drag & Drop
self.setDragEnabled(True)
self.setDragDropMode(QAbstractItemView.InternalMove)
@@ -102,6 +106,37 @@ class GuiDocTree(QTreeWidget):
self.theProject.setTreeOrder(theList)
return True
def getColumnSizes(self):
retVals = [
self.columnWidth(0),
self.columnWidth(1),
self.columnWidth(2),
]
return retVals
##
# Context Menu
##
def _openContextMenu(self, thePos):
sIDs = self.selectedIndexes()
print(sIDs)
ctxMenu = QMenu(self)
menuNewObject = QAction(QIcon.fromTheme("folder-new"), "New Object", ctxMenu)
# menuNewObject.triggered.connect(self.newProject)
ctxMenu.addAction(menuNewObject)
ctxMenu.exec_(self.viewport().mapToGlobal(thePos))
return
##
# Internal Functions
##
def _scanChildren(self, theList, theItem, theIndex):
tHandle = theItem.text(3)
nwItem = self.theProject.projTree[tHandle]
@@ -155,12 +190,4 @@ class GuiDocTree(QTreeWidget):
return selItem[0].text(3)
return None
def getColumnSizes(self):
retVals = [
self.columnWidth(0),
self.columnWidth(1),
self.columnWidth(2),
]
return retVals
# END Class GuiDocTree