Results 1 to 3 of 3

Thread: QItemDelegate's QComboBox default value?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2014
    Posts
    48
    Thanks
    23
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    Windows

    Question QItemDelegate's QComboBox default value?

    Is there a legitimate means of setting a models value via a delegated QComboBox's default value (within a QtableView)?
    Upon clicking the ComboBox, the model data is properly registered - but prior to this, the data is empty.

    This is because @ the comboBox's creation, the index is effectively '-1' correct?

    I have tried to emplace various calls to:
    QComboBox.setCurrentIndex(0) within the delegate, but because it has yet to return the editor object to the View, the signal for 'currentIndexChanged' is never called, and thus the data model is never updated.

    I suppose I could blunt code editing of the model data from the View class with hard strings for the default values - but I wondered if there was a means of keeping in 'sync' with the comboBox.


    [SIDE NOTE: Is it possible to set a stylesheet within the delegate for the combobox? Currently unable to with 'confinedCombo.setStyleSheet(...)']

    Thanks.

    Qt Code:
    1. class quiteANiceView(QtGui.QDialog, QtGui.QWidget):
    2. def __init__(self, iface, editorType, directory, parent=None):
    3. super(shapeCSVeditor, self).__init__(parent)
    4. self.iface = iface
    5. self.interpol = interpol()
    6. self.editorType = editorType
    7. self.directory = directory
    8. self.tableView = QtGui.QTableView(self)
    9. ...
    10. if 'Layer-Options' in self.editorType:
    11. self.tableView.setItemDelegateForColumn(1,confineComboDelegate(self.tableView))
    12. self.tableView.openPersistentEditor(self.tableData.index(row, 1)
    13. ...
    14.  
    15. class confineComboDelegate(QtGui.QItemDelegate):
    16. def __init__(self, parent):
    17. QtGui.QItemDelegate.__init__(self, parent)
    18. def createEditor(self, parent, option, index):
    19. confiningChoices = ['True','False']
    20. confineCombo = QtGui.QComboBox(parent)
    21. confineCombo.addItems(self.confiningChoices)
    22. confineCombo.currentIndexChanged[int].connect(self.currentIndexChanged)
    23. return confineCombo
    24. def setEditorData(self, editor, index):
    25. editor.blockSignals(True)
    26. try: idxConversion = self.confiningChoices.index(index.model().data(index,Qt.DisplayRole))
    27. except: idxConversion = 0
    28. editor.setCurrentIndex(int(idxConversion))
    29. editor.blockSignals(False)
    30. def setModelData(self, editor, model, index):
    31. model.setData(index, self.confiningChoices[editor.currentIndex()],Qt.EditRole)
    32. @QtCore.pyqtSlot(int)
    33. def currentIndexChanged(self):
    34. self.commitData.emit(self.sender())
    To copy to clipboard, switch view to plain text mode 
    Last edited by jkrienert; 28th January 2015 at 14:30.

Similar Threads

  1. QItemDelegate for painting QComboBox in QTreeWidget
    By naturalpsychic in forum Qt Programming
    Replies: 7
    Last Post: 23rd May 2011, 15:38
  2. QItemDelegate, QDataWidgetMapper and QComboBox
    By cydside in forum Qt Programming
    Replies: 7
    Last Post: 8th April 2009, 18:44
  3. QItemDelegate and default actions...
    By TemporalBeing in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2009, 17:45
  4. Editable QComboBox with QItemDelegate
    By Jmgr in forum Qt Programming
    Replies: 11
    Last Post: 10th December 2008, 09:21
  5. QComboBox QitemDelegate size
    By aekilic in forum Qt Programming
    Replies: 1
    Last Post: 6th December 2008, 16:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.