On Jan 25, 11:06 am, "Edward K. Ream" <[email protected]> wrote:
> I wonder whether it is possible to use > QPointershttp://doc.trolltech.com/4.4/qpointer.htmlto detect dead widgets in > PyQt4? > Anyone have experience with this? Apparently QPointer doesn't exist in PyQt. That makes sense: I'm not sure how you could wrap pointers in Python as can be done with C++. I tried my hand at writing my own wrapper class for Qt tree edit (QLineEdit) widgets:: class editWidgetSafePointer (QtCore.QObject): '''A class to protect references to edit widgets.''' def __init__ (self,item,e,w): # g.trace('editWidgetSafePointer.__init__',w) self._item = item self._e = e self._w = w def __nonzero__ (self): item,e,w = self._item,self._e,self._w item2 = w.currentItem() e2 = w.itemWidget(item,0) val = item2 == item and e2 and e2 == e return g.choose(val,1,0) def __getattr__ (self,name): return getattr(self._e,name) def __setattr__ (self,name,val): if name in ('_item','_e','_w'): QtCore.QObject.__setattr__(self, name, val) else: setattr(self._e,name,val) Somewhat amusingly, this fails: QTreeWidget politely informs me that that underlying tree widget has been deleted. Maybe this could be fixed by making it a subclass of QLineEdit, but I think this approach is too clever by half. Indeed, the find logic is caching a widget that will die when Qt is used. That's a fundamental mistake and it's not good to paper over it. Edward --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "leo-editor" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en -~----------~----~----~----~------~----~------~--~---
