33 from python_qt_binding.QtCore
import Slot, QMimeData, QModelIndex, Qt, qWarning
34 from python_qt_binding.QtGui
import QDrag, QIcon
35 from python_qt_binding.QtWidgets
import QAction, QHeaderView, QMenu, QTreeView
41 super(MessageTreeWidget, self).
__init__(parent)
42 self.setDragEnabled(
True)
43 self.sortByColumn(0, Qt.AscendingOrder)
46 setSectionResizeMode = self.header().setSectionResizeMode
47 except AttributeError:
48 setSectionResizeMode = self.header().setResizeMode
49 setSectionResizeMode(QHeaderView.ResizeToContents)
50 self.header().setContextMenuPolicy(Qt.CustomContextMenu)
51 self.header().customContextMenuRequested.connect(
61 index = self.currentIndex()
62 if not index.isValid():
65 item = self.model().itemFromIndex(index)
66 path = getattr(item,
'_path',
None)
68 qWarning(
'MessageTreeWidget.startDrag(): no _path set on item %s' % item)
72 data.setText(item._path)
75 drag.setMimeData(data)
83 menu.exec_(self.mapToGlobal(pos))
86 if self.selectionModel().hasSelection():
97 def recursive_set_expanded(index):
98 if index != QModelIndex():
99 self.setExpanded(index, expanded)
100 recursive_set_expanded(index.child(0, 0))
101 for index
in self.selectedIndexes():
102 recursive_set_expanded(index)
110 action_toggle_auto_resize = menu.addAction(
'Auto-Resize')
111 action_toggle_auto_resize.setCheckable(
True)
112 auto_resize_flag = (self.header().resizeMode(0) == QHeaderView.ResizeToContents)
113 action_toggle_auto_resize.setChecked(auto_resize_flag)
115 action_toggle_sorting = menu.addAction(
'Sorting')
116 action_toggle_sorting.setCheckable(
True)
117 action_toggle_sorting.setChecked(self.isSortingEnabled())
120 action = menu.exec_(self.header().mapToGlobal(pos))
123 if action
is action_toggle_auto_resize:
125 self.header().setResizeMode(QHeaderView.Interactive)
127 self.header().setResizeMode(QHeaderView.ResizeToContents)
129 elif action
is action_toggle_sorting:
130 self.setSortingEnabled(
not self.isSortingEnabled())