models & editors in PyQt4

Skink spam at me.please
Wed Aug 30 11:58:40 EDT 2006


David Boddie wrote:
> 
> It should be OK - it shouldn't crash, anyway. It depends on the view
> doing the right thing when it finds that it hasn't received an editor
> widget.
> 
> You could create an empty placeholder widget in the createEditor()
> method, call QColorDialog.getColor() with the existing color from the
> model in setEditorData(), record the color returned by the dialog in
> some internal instance variable, and finally set the data in the model
> when setModelData() is called:
> 
> class ColorProperty(Property):
>   ...
>   def createEditor(self, parent, option, index):
>       return QtGui.QWidget(parent)
>   def setEditorData(self, editor, index):
>       self.color = QtGui.QColorDialog.getColor(
>           index.model().getObjectData(self.name()))
>   def setModelData(self, editor, model, index):
>       if self.color.isValid():
>           index.model().setObjectData(self.name(), self.color)

thanks for tip, i'll check it how it works.

>   ...
> 
> I find it strange that you have to triple-click to edit any of the
> items in your example. Do you see the same behaviour?
oh, this is default Qt behavoiur: first click selects row, second select 
editor (for ColorProperty, IntProperty & StringProperty you can now 
change the value) but third click is required only for properties w/ 
QCombobox editor (EnumProperty & BooleanProperty) ...

skink

> 
> David
> 



More information about the Python-list mailing list