PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 373 - Segfault with color editor factory example
: Segfault with color editor factory example
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: PySide
: 0.4.1
: PC Linux
: P3 normal
Assigned To: renato filho
:
:
:
  Show dependency treegraph
 
Reported: 2010-09-21 14:41 EEST by Bajusz Tamás
Modified: 2010-10-13 13:48 EEST (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bajusz Tamás 2010-09-21 14:41:31 EEST
#Clicking into a color editor segfaults with PySide, but not with PyQt4.

USE_PYSIDE = False
USE_PYSIDE = True

if USE_PYSIDE:
    from PySide import QtCore
    from PySide import QtGui
    from PySide.QtCore import QProperty as pyqtProperty
    qcolor = QtGui.QColor
else:
    import sip
    sip.setapi('QString', 2)
    sip.setapi('QVariant', 2)
    from PyQt4 import QtCore
    from PyQt4 import QtGui
    from PyQt4.QtCore import pyqtProperty
    qcolor = QtCore.QVariant.Color


class ColorListEditor(QtGui.QComboBox):
    def __init__(self, parent):
        QtGui.QComboBox.__init__(self, parent)
        self.populateList()

    def getColor(self):
        return self.itemData(self.currentIndex(),
                                QtCore.Qt.DecorationRole) #.toPyObject()

    def setColor(self, color):
        self.setCurrentIndex(self.findData(color, QtCore.Qt.DecorationRole))

    color = pyqtProperty('QColor', getColor, setColor, user=True)

    def populateList(self):
        for i, name in enumerate(QtGui.QColor.colorNames()):
            self.insertItem(i, name)
            self.setItemData(i, QtGui.QColor(name),
                                QtCore.Qt.DecorationRole)


class ColorListCreator(QtGui.QItemEditorCreatorBase):
    def __init__(self):
        QtGui.QItemEditorCreatorBase.__init__(self)

    def createWidget(self, parent):
        return ColorListEditor(parent)


class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        factory = QtGui.QItemEditorFactory()
        colorListCreator = ColorListCreator()
        factory.registerEditor(qcolor, colorListCreator)
        QtGui.QItemEditorFactory.setDefaultFactory(factory)
        self.createGUI()

    def createGUI(self):
        data = ((self.tr('Alice'), QtGui.QColor('aliceblue')),
                (self.tr('Neptun'), QtGui.QColor('aquamarine')),
                (self.tr('Ferdinand'), QtGui.QColor('springgreen')))
        table = QtGui.QTableWidget(3, 2)
        table.setHorizontalHeaderLabels(['Name', 'Hair Color'])
        table.verticalHeader().setVisible(False)
        table.resize(150, 50)
        for i, (name, color) in enumerate(data):
            nameItem = QtGui.QTableWidgetItem(name)
            colorItem = QtGui.QTableWidgetItem()
            colorItem.setData(QtCore.Qt.DisplayRole, color)
            table.setItem(i, 0, nameItem)
            table.setItem(i, 1, colorItem)
        table.resizeColumnToContents(0)
        table.horizontalHeader().setStretchLastSection(True)
        layout = QtGui.QGridLayout()
        layout.addWidget(table, 0, 0)
        self.setLayout(layout)
        self.setWindowTitle('Color Editor Factory')


if __name__ == '__main__':

    import sys

    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())
Comment 1 renato filho 2010-09-24 16:46:26 EEST
fixed on shiboken commit:

commit 2177dc5fded5e4251bbc1a3793b5a8e77dbc20fd
Author: renatofilho <renato.filho@openbossa.org>
Date:   Fri Sep 24 16:06:48 2010 -0300


pyside commit:

commit 41bd89393e3203c027cb659771e390a7101c5fc4
Author: renatofilho <renato.filho@openbossa.org>
Date:   Fri Sep 24 15:59:11 2010 -0300
Comment 2 renato filho 2010-10-13 13:48:53 EEST
released on PySide 0.4.2