def edit_cell ( self, parent, row, column ): """ Returns the editor widget to use for editing a specified cell's value. """ self.cell_row = self.data_row_for( row ) # Get the editor factory to use. If none, exit (read-only cell): editor_factory = self.grid_adapter.get_editor( self.cell_row, column ) if editor_factory is None: return None # Create the requested type of editor from the editor factory: # Note: We save the editor reference so that the editor doesn't get # garbage collected too soon. self.cell_column = column object, name = self.grid_adapter.get_alias( self.cell_row, column ) editor = editor_factory.simple_editor( self.ui, object, name, '' ).set( item = self.item, object_name = '' ) # Tell the editor to actually build the editing widget: editor.prepare( control_adapter( parent ) ) # Make sure that the editor is a control (and not a layout): self._editor = editor control = editor.control if not isinstance( control, QWidget ): layout = control control = QWidget( parent ) control.setLayout( layout ) layout.setContentsMargins( 5, 0, 5, 0 ) control._editor = editor # Adjust the row height of the grid row to fit the editor control: height = control.height() if height > self.height: if (self.height - height) <= 4: # If the difference is not too great, then we will just adjust # the grid height to accomodate it: self.row_height( height ) else: # Otherwise, just adjust the height of this row temporarily: control._row = row self.control.verticalHeader().resizeSection( row, height ) # Resize the grid column width to fit the editor if necessary: width = control.width() header = self.control.horizontalHeader() column_width = header.sectionSize( column ) if width > column_width: control._column = column control._width = column_width header.resizeSection( column, width ) # Return the editing widget as the result: return control