[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)

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

    def id(self, id):
        print 'setting value'

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

    def text(self, text):

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

    def tooltip(self, tooltip):

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

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

    def perform(self):
        raise NotImplementedError

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

    i = Indicator(text='xxx')


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