I am using Qt 4.7.
I have a model that I show in a QTableView in two columns, and my goal is to provide inline editing of this model in my QTableView .
+-----------------+----------------+ | Axis position | Axis range | +-----------------+----------------+ | Left | Fixed [0,1] | | Left | Source: SRC1 | | Right | Source: SRC2 | | Left | Fixed [5,10] | +-----------------+----------------+
The first column can be edited using a simple QComboxBox to switch between Right and Left, and it works quite well. The problem is with my second column, which can be edited using a custom widget.
This widget is simple; it describes a range. Thus, QComboBox selects the type of range ("Fixed": values ββare set by the user "Source": the value is dynamically changed from the minimum / maximum value of the source).
Here is the source code of my custom widget:
class RangeEditor : public QWidget { Q_OBJECT public: RangeEditor( ... ); ~RangeEditor(); public: CurveView::ConfigAxes::Range range () const; QVariant minimum() const; QVariant maximum() const; DataModel* model () const; void range ( CurveView::ConfigAxes::Range range ); void minimum( QVariant minimum ); void maximum( QVariant maximum ); void model ( DataModel* model ); public slots: void rangeTypeChanged( int type ); private:
Ok, so now I created a QStyledItemDelegate to provide a custom editor view for my columns. Here is how I did it:
class ConfigAxesDelegate : public QStyledItemDelegate { public: ConfigAxesDelegate( ... ); ~ConfigAxesDelegate(); public: virtual QWidget* createEditor ( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const; virtual void setEditorData ( QWidget* editor, const QModelIndex& index ) const; virtual void setModelData ( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const; virtual void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const; }; QWidget* ConfigAxesDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const { if ( index.column()==0 )
Basically, what I get is a single pixel height editor.
Here is a screenshot of the result: 
I tried changing updateEditorGeometry to the following:
void ConfigAxesDelegate::updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const { QRect r = option.rect; r.setSize( editor->sizeHint() ); editor->setGeometry( r ); }
The size problem seems to be fixed, but not the position: 
I feel lost because I donβt know if a problem arises from my custom widget (not providing enough information for Qt to correctly calculate its position) or presentation (maybe some fields that may lead to a reduction in the size of the editor), or updateEditorGeometry()
Any help is much appreciated, thanks for reading!