-
Notifications
You must be signed in to change notification settings - Fork 2
/
myTreeViewCode.py
713 lines (625 loc) · 28.3 KB
/
myTreeViewCode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtCore import QVariant
from pickle import *
import photo_database_code
from photo_database_code import *
SortRole = Qt.UserRole + 1
class PyMimeData(QMimeData):
""" The PyMimeData wraps a Python instance as MIME data.
"""
# The MIME type for instances.
# MIME_TYPE = QString('application/x-ets-qt4-instance')
''' This class is pretty much as I found it. However all of the stuff
about serializing the data does not work. The TreeItem indexes passed along by the
start Drag functions can not be serialized.
This module works because 1) We are draging and dropping within the same program
and 2) It perserves a copy of the data here in the INSTANCE variable. On drop we then
retrieve that data.
'''
MIME_TYPE = 'application/x-ets-qt5-instance' # maybe qt5
def __init__(self, data=None):
""" Initialise the instance.
"""
# Required
QMimeData.__init__(self)
# Keep a local reference to be returned if possible.
# it because we do this that this class works at all. The tree items
# can not be pickled. At least as they stand now. I believe some methods can
# be added to the TreeItem class so they cn be serialized.
self._local_instance = data
if data is not None:
# We may not be able to pickle the data.
try:
pdata = dumps(data)
except:
return
# This format (as opposed to using a single sequence) allows the
# type to be extracted without unpickling the data itself.
self.setData(self.MIME_TYPE, dumps(data.__class__) + pdata)
print("exiting __init__ of pymimedata")
@classmethod
def coerce(cls, md):
""" Coerce a QMimeData instance to a PyMimeData instance if
possible.
"""
# See if the data is already of the right type. If it is then we know
# we are in the same process.
print("In classmethod - PyMimeData")
if isinstance(md, cls):
return md
# See if the data type is supported.
if not md.hasFormat(cls.MIME_TYPE):
return None
nmd = cls()
nmd.setData(cls.MIME_TYPE, md.data())
return nmd
def instance(self):
""" Return the instance.
"""
# print("Entered instance of PyMimeData")
if self._local_instance is not None:
return self._local_instance
# This is where we get the mimedata back on dropping.
io = StringIO(str(self.data(self.MIME_TYPE)))
try:
# Skip the type.
load(io)
# Recreate the instance.
return load(io)
except:
print("load failed - instance - PyMimeData")
pass
return None
def instance_type(self):
""" Return the type of the instance.
"""
if self._local_instance is not None:
return self._local_instance.__class__
try:
return loads(str(self.data(self.MIME_TYPE)))
except:
print("instance_type, load failed.")
pass
return None
'''
Note. TreeItem was built subclassing Qobject. Then at the last it was converted to subclass QStandardItem.
Most likely it could be simplified.
Some methods may need to renamed to over write QStandardItem methods that accomplish the same thing.
'''
class TreeItem(QStandardItem):
def __init__(self, data, parent=None):
# required
super(TreeItem, self).__init__(parent)
self.parentItem = parent
self.itemData = data
self.childItems = []
# set default setting
self.DropEnabled = False # this is needed because we are rolling our own Class, Pre QStandardItem
self.Checkstatus = Qt.Unchecked # this is needed because we are rolling our own Class basee on QObject.
def appendChild(self, child):
# required - loads initial data
# from drag drop model
self.childItems.append(child)
def child(self, row, column=None): # Column is not used in this implementation, put parameter kept to be compatible with prototype.
# required
# from simple and editable examples
return self.childItems[row]
def childCount(self):
# required
# from simple and editable examples
return len(self.childItems)
def columnCount(self):
# required
return len(self.itemData)
def data(self, column):
# Required
# from simple and editable models
try:
return self.itemData[column]
except IndexError:
print("Index Error - data in Tree Item")
return None
def insertChildren(self, data, position, rowcount, columns, acceptdrops):
# from editable model
# required
# Added acceptdrops to standard prototypes, as we need this set for nodes with children (containers) to make
# Drag and Drop more intuitive. People expect to be able to drop ONTO containers.
if position < 0 or position > len(self.childItems):
return False
for row in range(rowcount): # row count is always 1 in our model.
item = TreeItem(data, self)
item.DropEnabled = acceptdrops
self.childItems.insert(position, item)
return True
def parent(self):
# Required
# from simple and editable model
return self.parentItem
def removeChildren(self, position, count):
# from editable model
# required
if position < 0 or position + count > len(self.childItems):
return False
for row in range(count):
self.childItems.pop(position)
return True
def removeChild(self, row):
# required
# from drag drop model
value = self.childItems[row]
self.childItems.remove(value)
return True
def row(self):
# required
if self.parentItem:
return self.parentItem.childItems.index(self)
return 0
def setDropEnabled(self, value):
# required
self.DropEnabled = value
def isDropEnabled(self):
# required
return self.DropEnabled
def checkboxstate(self):
# required if you want check boxes
# because we are rolling our own treeitem class
return self.Checkstatus
def setcheckboxstate(self, value):
# required if you want check boxes
self.Checkstatus = value
return True
''' Items below this point are most likely not needed
in this implementation. May be need in others, especially those that use columns
After full confirmaton removed '''
def __len__(self):
# print(len(self.childItems))
return len(self.childItems) + 1
def childAtRow(self, row):
# from Drag Drop Model
# looks to be duplicate of Child.
print("Entered ChildAtRow - Tree Item")
return self.childItems[row]
def childNumber(self):
print("Entered Child number - Tree Item")
# from simple and editable examples
if self.parentItem is not None:
return self.parentItem.childItems.index(self)
def insertColumns(self, position, columns):
print("In insert column,- treeItem")
# from editable model
# this is likely not used in our setup
if position < 0 or position > len(self.itemData):
return False
for column in range(columns):
self.itemData.insert(position, None)
for child in self.childItems:
child.insertColumns(position, columns)
return True
def removeColumns(self, position, columns):
print("In RemoveColumns - TreeItem")
# from editable model
# likely not used in our set up
if position < 0 or position + columns > len(self.itemData):
return False
for column in range(columns):
self.itemData.pop(position)
for child in self.childItems:
child.removeColumns(position, columns)
return True
def setData(self, column, value):
# from editable model
print("Entered setData in TreeItem")
if column < 0 or column >= len(self.itemData):
return False
self.itemData[column] = value
return True
class TreeModel(QtCore.QAbstractItemModel):
def __init__(self, headers, data, mydb, parent=None):
super(TreeModel, self).__init__(parent)
self.mydb = mydb # preserve database object so it can be accessed and passed down.
rootData = [header for header in headers]
self.rootItem = TreeItem(rootData) # this is required because setupModelData needs a parent.
self.rootItem.setDropEnabled(False)
self.setupModelData(data, self.rootItem)
self.columns = 4
print("exiting TreeModel __init__")
def columnCount(self, parent=None):
# Required
# from Simple tree model, similar to Editable tree model
if parent.isValid():
return parent.internalPointer().columnCount()
else:
return self.rootItem.columnCount()
def data(self, index, role=None):
# required
# This is good place to see how ROLES really work. data that is used for a specific purpose is accessed
# by requesting it. The ROLE is an integer that has been defined to refer to that data. In this case when
# the model requests data of SORTROLE we return item.data(2). We could return anything but the Model is
# going to use if for sorting. When CheckStateRole is requested it is going to use that to populate the check
# box
row = index.row()
column = index.column()
if role == Qt.DecorationRole:
# print("Decoration role requested")
return None
if role == Qt.TextAlignmentRole:
return QVariant(int(Qt.AlignTop | Qt.AlignLeft))
if not index.isValid():
print("invalid index data request")
return None
item = self.getItem(index)
if role == SortRole:
# print("Sort Role requested")
# print(item.data(2))
return item.data(2)
if role == Qt.CheckStateRole and column == 0:
return item.checkboxstate()
if role != Qt.DisplayRole:
# print("non Disply role requested" + str(role))
return None
temp = item.data(index.column())
return temp
def flags(self, index):
# required
""" Flags are what model uses internally to decide what it is allowed to do or not. They are integers. QT
has definded these strings to have specific values. This makes things easier then trying to rember the
number value. It is a more complex than this, so read up on it."""
node = self.nodeFromIndex(index)
defaultFlags = QAbstractItemModel.flags(self, index) # from drag drop model
if not index.isValid():
# print("index is not valid - flags - TreeModel")
return defaultFlags # returning a valid flag keeps things from crashing.
if node.isDropEnabled():
return QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsDragEnabled | QtCore.Qt.ItemIsDropEnabled | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | defaultFlags
else:
return QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsDragEnabled | QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | defaultFlags
def getItem(self, gtindex):
# required
# from editable model
if gtindex.isValid():
item = gtindex.internalPointer()
if item:
return item
return self.rootItem
def headerData(self, section, orientation, role=Qt.DisplayRole):
# required
# from Simple tree model and editable model
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
return self.rootItem.data(section)
return None
def index(self, row, column, parent=QModelIndex()):
# required
# from editable model
if parent.isValid() and parent.column() != 0: # we want the index the Row, not specific items
return QModelIndex()
parentItem = self.getItem(parent)
childItem = parentItem.child(row)
if childItem:
return self.createIndex(row, column, childItem) # colomn is always zero if we are here
else:
return QModelIndex()
def insertRow(self, data, row, parent, acceptdrops=False): # modified from base method to include acceptdrops
# required
# from drag Drop model
return self.insertRows(data, row, 1, acceptdrops, parent)
def insertRows(self, data, position, rows, acceptdrops, irparentindex=QModelIndex()): # modified from base method
# Required
# from editable model
parentItem = self.getItem(irparentindex)
self.beginInsertRows(irparentindex, position, position + rows - 1)
success = parentItem.insertChildren(data, position, rows, self.rootItem.columnCount(), acceptdrops)
self.endInsertRows()
return success
def nodeFromIndex(self, index):
# Required
# From Drag Drop Model
return index.internalPointer() if index.isValid() else self.rootItem
def parent(self, index):
# Required
# from simple tree model and editable model index
if not index.isValid():
return QtCore.QModelIndex()
childItem = self.getItem(index)
parentItem = childItem.parent()
if parentItem == self.rootItem:
return QtCore.QModelIndex()
return self.createIndex(parentItem.row(), 0, parentItem)
def removeRows(self, position, rows, parent=QModelIndex()):
# required
# from editable model
parentItem = self.getItem(parent)
self.beginRemoveRows(parent, position, position + rows - 1)
success = parentItem.removeChildren(position, rows)
self.endRemoveRows()
return success
def rowCount(self, parent=QModelIndex()):
# required
# From Simple tree model
if parent.column() > 0:
return 0
if not parent.isValid():
rcparentItem = self.rootItem
else:
rcparentItem = self.getItem(parent)
return rcparentItem.childCount()
def setData(self, index, value, role=Qt.EditRole):
# required
# from editable model
item = self.getItem(index)
if role == Qt.EditRole:
result = item.setData(index.column(), value)
self.dataChanged.emit(QModelIndex(), index) # Let the world know we update the View.
elif role == Qt.CheckStateRole:
result = item.setcheckboxstate(value)
self.dataChanged.emit(QModelIndex(), index) # Let the world know we update the View.
else:
return False
if result:
self.dataChanged.emit(index, index)
return result
''' items below are for drag and drop'''
def supportedDropActions(self):
# required
# from drag drop model
return Qt.CopyAction | Qt.MoveAction
def mimeTypes(self):
# required.
# From Drag Drop model
types = []
types.append('application/x-ets-qt5-instance')
return types
def mimeData(self, indices):
# required
# from drag drep model
# print("Enetered mimeData - TreeModel")
mimeData = PyMimeData(indices)
return mimeData
def canDropMimeData(self, data, action: Qt.DropAction, row: int, column: int, parent: QModelIndex) -> bool:
# required
droptarget = self.nodeFromIndex(parent)
dropok = droptarget.isDropEnabled()
return dropok
def dropMimeData(self, mimedata, action, row, column, parentIndex):
# from drag drop model
# print("Entered drop MimeData")
# print("Target Row is " + str(row))
# print("Drop MimeData Action " + str(action))
if row == -1: # this means we are dropping ONTO the target, not below so insert at top of list.
row = 0
if action == Qt.IgnoreAction:
print("returned for Ignore Action")
return True
dragNode = mimedata.instance()
index = len(dragNode) - 1 # number items we have to process
result = True
dragNodeParent = None
'''
mimedata turns a list of TreeItems. It returns child items first and parent (top level) items last
so we have to process in reverse order '''
while index >= 0:
onenode = self.nodeFromIndex(dragNode[index])
if dragNodeParent is None:
dragNodeParent = onenode.parentItem # populates with first item processed
if dragNodeParent is not onenode.parentItem:
index -= 1
continue # discard this item and go back for more
oneresult = self.dropManyRows(onenode, row, parentIndex) # takes a node, not an index
index -= 1
if not oneresult:
result = False
return result
def dropManyRows(self, dragNode, row, parentIndex, result=True):
newdata = dragNode.itemData
newparent = self.nodeFromIndex(parentIndex)
if dragNode.childCount() > 0:
# dragging a container with children
childresult = self.dropOneRow(newdata, row, parentIndex,
True) # process the parent node, should accept drops
if childresult is None:
print("drop one Row failed in Drop many Rows")
result = False
# now update the underlying database
db_row_to_update = newdata[1]
newparent_row = newparent.itemData[1]
self.mydb.update_parent_tag(db_row_to_update,
newparent_row) # We only need to update database for top item in move
# now setup to process the child nodes
dragchilds = dragNode.childItems
for childnode in dragchilds:
if childnode.childCount() > 0:
childresult2 = self.dropManyRows2(childnode, 0, childresult, result) # We are going Two levels deep
if childresult2 is None:
print("Drop Many rows 2 returned False")
result = False
else:
childdata = childnode.itemData
childresultx = self.dropOneRow(childdata, 0, childresult) # also insert into row 0 Model will sort
if childresultx is None:
result = False # If any opertion fails then whole move fails
return result
else:
dropresult = self.dropOneRow(newdata, row, parentIndex)
if dropresult is None:
result = False
# now update the underlying database
db_row_to_update = newdata[1]
newparent_row = newparent.itemData[1]
self.mydb.update_parent_tag(db_row_to_update,
newparent_row) # We only need to update database for top item in move
return result
def dropManyRows2(self, dragNode, row, parentIndex, result):
# print("in Drop Many TWO")
newdata = dragNode.itemData
if dragNode.childCount() > 0:
childresult = self.dropOneRow(newdata, row, parentIndex, True)
if childresult is None:
result = False
print("drop one failed in Drop Many 2")
dragchilds = dragNode.childItems
for childnode in dragchilds:
if childnode.childCount() > 0:
childresultz = self.dropManyRows2(childnode, 0, childresult,
result) # we are going three or more levels deep
if childresultz is None:
result = False
else:
childdata = childnode.itemData
childresultx = self.dropOneRow(childdata, 0, childresult) # also insert into row 0 Model will sort
if childresultx is None:
print("drop one failed in Dropmanyrows 2 -xxx")
result = False # If any opertion fails then whole move fails
return result
else:
childresult = self.dropOneRow(newdata, row, parentIndex)
if childresult is None:
result = False
return result
def dropOneRow(self, newdata, row, dpparentIndex, acceptdrop=False):
# required
result = self.insertRow(newdata, row, dpparentIndex, acceptdrop) # this inserts the row into the Model
self.dataChanged.emit(QModelIndex(), dpparentIndex) # Let the world know we update the Model
if result:
# we need to create an index that point to the object just created, in case this a container row.
newitemhasindex = self.hasIndex(row, 0, dpparentIndex)
if newitemhasindex:
newitemindex = self.index(row, 0, dpparentIndex)
if newitemindex.isValid():
return newitemindex
else:
print("invalid index created in drop one row")
else:
print("DropOnerow, new items does not have an index")
else:
print("Insert Row failed in dropOneRow")
return
def setupModelData(self, data2, root):
# required for my implementation.
# this is unique to this implementation, Every implematation will need it own way of loading data into model
# This loads loads the model with the data from the SQL Query
seen = {} # dictionary of row objects that have been inserted.
# we can not load a row unless the parent has already been inserted. This keeps track of what has been inserted.
while data2:
row = data2.pop(0)
if row[1] == 0: # Level data - unique to my data
parent = root # parent is a standard TreeItem object
else:
parent_id = row[4] # Parent ID in tag table
if parent_id not in seen: # cannot insert child if parent not present
data2.append(row) # add it back on list to imported
continue # circle back around for next item
parent = seen[parent_id] # model row item object of parent
database_id = row[0] # tag database row id the row of source data
if row[1] == 0: # Level - Base
# print("inserting base row")
treedata = (row[3], str(row[0]), row[7], str(row[4]))
treedataobj = TreeItem(treedata, parent)
treedataobj.setDropEnabled(True)
# treedataobj.setCheckable(True)
parent.appendChild(treedataobj)
else:
treedata = (row[3], str(row[0]), row[7], str(row[4]))
treedataobj = TreeItem(treedata, parent) # this will append item into tree
if row[2] == 0: # is not group row, ie no children
# treedataobj.setCheckState(False)
# treedataobj.setCheckable(True)
treedataobj.setDropEnabled(False) # items which are not groups should not accept drops.
# treedataobj.setDragEnabled(False)
# item_id.setDropEnabled(False)
# treedataobj.setData(str(row[0]), Qt.DisplayRole)
else:
treedataobj.setDropEnabled(True)
parent.appendChild(treedataobj)
seen[database_id] = treedataobj
print("all tags imported")
""" Stuff below this line does not appear to be required in my installation
They were taken from various models that went into this implementation
and may have been needed at one time.
Some appear to be for moving columns such as in table views so are left
here for others to look at
"""
def insertColumns(self, position, columns, parent=QModelIndex()):
print("Entered insertColumns - TreeModel")
# reviewed
self.beginInsertColumns(parent, position, position + columns - 1)
success = self.rootItem.insertColumns(position, columns)
self.endInsertColumns()
return success
def setHeaderData(self, section, orientation, value, role=Qt.EditRole):
print("Entered setHeaderData - Tree Model")
# reviewed
if role != Qt.EditRole or orientation != Qt.Horizontal:
return False
result = self.rootItem.setData(section, value)
if result:
self.headerDataChanged.emit(orientation, section, section)
return result
def removeColumns(self, position, columns, parent=QModelIndex()):
print("removeColumns - TreeModel ")
# from editable model
# reviewed.
self.beginRemoveColumns(parent, position, position + columns - 1)
success = self.rootItem.removeColumns(position, columns)
self.endRemoveColumns()
if self.rootItem.columnCount() == 0:
self.removeRows(0, self.rowCount())
return success
def removeRow(self, row, parentIndex=QModelIndex()):
# from drag Deop Model
print("in Remove Row")
return self.removeRows(row, 1, parentIndex)
class myTreeView(QTreeView):
def __init__(self, parent=None):
super(myTreeView, self).__init__(parent)
mydbpath = photo_database_code.create_data_dir()
myphotodatabase = PhotoDatabase(mydbpath)
self.mydb = myphotodatabase
print("database to be used is " + myphotodatabase.database)
myphotodatabase.connect()
curr = myphotodatabase.cursor
sq = "Select * from tags ORDER BY TagClass, level, tag"
myphotodatabase.execute(sq)
data2 = curr.fetchall()
# print(len(data2))
myphotodatabase.close_database()
headers = ("Tag", "Database Row", "Sort Column", "DB Parent Row")
# proxy sortfilter stuff
sourceModel = TreeModel(headers, data2, myphotodatabase)
proxyModel = QSortFilterProxyModel()
proxyModel.setSortRole(SortRole)
proxyModel.setSourceModel(sourceModel)
self.setModel(proxyModel)
self.setSortingEnabled(True)
self.sortByColumn(2, Qt.AscendingOrder)
self.setDragEnabled(True)
self.setAcceptDrops(True)
self.showDropIndicator()
self.setDropIndicatorShown(True)
self.setDragDropMode(QAbstractItemView.InternalMove)
self.expandToDepth(1)
self.setHeaderHidden(True)
self.resizeColumnToContents(0)
self.setColumnHidden(3, True) # hide all the columns we do not want to show.
self.setColumnHidden(2, True) # these columns carry data we need elsewhere
self.setColumnHidden(1, True)
self.setUniformRowHeights(True)
self.setEditTriggers(QAbstractItemView.NoEditTriggers) # otherwise the built in edit of items happens, model doesn't handle this
self.setExpandsOnDoubleClick(True) # only works if edit triggers is off
self.setAlternatingRowColors(True)
self.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)
self.setVerticalScrollMode(QAbstractItemView.ScrollPerItem)
self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) # must be this for our implementation, other setting disable delete in drag and drop
self.setSelectionMode(QAbstractItemView.ContiguousSelection)
self.setAnimated(True)
self.setAllColumnsShowFocus(True)
def change(self, topLeftIndex, bottomRightIndex):
print("Entered Change in TreeView")
self.update(topLeftIndex)
self.expandAll()
self.expanded()
def expanded(self):
print("Entered Expanded in TreeView")
for column in range(self.model().columnCount(QModelIndex())):
self.resizeColumnToContents(column)