[PyQt] help with dip and PyQt4 widgets

Lic. José M. Rodriguez Bacallao jmrbcu at gmail.com
Fri Jul 8 14:49:30 BST 2011


hi folks, I am creating a composite widget with PyQt4 and Dip, the
problem I have is that when I use dip properties for setting PyQt4
properties in the constructor I am getting an error saying that the
underlying C++ object has been delete, I think this is due to the way
dip works because it call properties methods before the actual Qt4
widget as been created when I pass an initial value in the
constructor. When I construct the object with properties initial
values and the use the properties accesors to set the value, this
doens't happen. So, my question is, which is the right way to
construct a custom composite widget with dip?

# dip imports
from dip.model import Model, Instance, Str

# PyQt4 imports
from PyQt4 import QtCore, QtGui

class Indicator(QtGui.QToolButton, Model):

    # the indicator identifier, it must be unique for all indicators
    id = Str()

    # the indicator text, this text will be shown
    # beside the icon if one is defined
    text = Str()

    # the indicator tooltip
    tooltip = Str()

    # the indicator icon
    icon = Instance(QtGui.QIcon)

    @id.getter
    def id(self):
        print 'getting value'
        return self.objectName()

    @id.setter
    def id(self, id):
        print 'setting value'
        self.setObjectName(id)

    @text.getter
    def text(self):
        return self.text()

    @text.setter
    def text(self, text):
        self.setText(text)

    @tooltip.getter
    def tooltip(self):
        return self.toolTip()

    @tooltip.setter
    def tooltip(self, tooltip):
        self.setToolTip(tooltip)

    @icon.getter
    def icon(self):
        return self.icon()

    @icon.setter
    def icon(self, icon):
        self.icon = icon

    def perform(self):
        raise NotImplementedError

if __name__ == '__main__':
    app = QtGui.QApplication([])

    i = Indicator(text='xxx')
    i.show()

    app.exec_()

-- 
Lic. José M. Rodriguez Bacallao
Centro de Biofisica Medica
-----------------------------------------------------------------
Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo.

Recuerda: El arca de Noe fue construida por aficionados, el titanic
por profesionales
-----------------------------------------------------------------


More information about the PyQt mailing list