Coverage for larch/qtlib/delegates.py: 0%

29 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-10-16 21:04 +0000

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3""" 

4Qt delegates 

5============ 

6""" 

7from __future__ import absolute_import, division 

8from silx.gui import qt 

9 

10 

11class ComboBoxDelegate(qt.QStyledItemDelegate): 

12 

13 def __init__(self, parent=None): 

14 super(ComboBoxDelegate, self).__init__(parent=parent) 

15 

16 def createEditor(self, parent, option, index): 

17 editor = qt.QComboBox(parent) 

18 editor.setMinimumHeight(25) 

19 editor.currentIndexChanged.connect(self.commitDataAndClose) 

20 return editor 

21 

22 def setEditorData(self, editor, index): 

23 model = index.model() 

24 values = model.data(index, qt.Qt.EditRole) 

25 currentText = model.data(index, qt.Qt.DisplayRole) 

26 editor.blockSignals(True) 

27 editor.addItems(values) 

28 editor.setCurrentText(currentText) 

29 editor.blockSignals(False) 

30 

31 def setModelData(self, editor, model, index): 

32 value = editor.currentText() 

33 model.setData(index, value, qt.Qt.EditRole) 

34 

35 def updateEditorGeometry(self, editor, option, index): 

36 editor.setGeometry(option.rect) 

37 

38 def commitDataAndClose(self): 

39 editor = self.sender() 

40 self.commitData.emit(editor) 

41 self.closeEditor.emit(editor) 

42 

43 

44if __name__ == '__main__': 

45 pass