Just what I was looking for! I'll give this a try.
--Susan
Just what I was looking for! I'll give this a try.
--Susan
Unfortunately, this method never gets called!!! I am not sure why. I have an example MVC implementation from a training class I attended and the delgates never implemented this method and the editor (spinbox or combo) was always sized correctly... Ideas?
No idea why it isn't called, but take a look at the Spin Box delegate example in the Qt Demos ( Item Views section ).
It does something similar to what you want.
I think its not called because in the Qt source for QItemDelegete, it isn't virtual!! (it is supposed to be). Stepping through the Qt code for creating the delegate editor, it invokes QItemDelegate::updateEditorGeometry, not my derivation! I'll look at the example that you site, but I think this is the culprit. My example from the class is pretty straight forward too and doesn't event reimplement that method...![]()
This is the member description from QItemDelegate. As you can see it is virtual. Also this member is public and const. Perhaps you didn't declare it as public in your class?void QItemDelegate::updateEditorGeometry ( QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index ) const [virtual] Updates the editor for the item specified by index according to the style option given.
Reimplemented from QAbstractItemDelegate.
Actually you're right. I just took a look at QItemDelegate.h and the member is not virtual.
But it is in QAbstractItemDelegate. Couldn't you derive your delegate from QAbstractItemDelegate instead?
smacchia (9th April 2007)
Oh duh - it was the "const". Thanks! It works great now.
i got a similar problem with delegates and a QTreeView, but i'm using editing widgets that contain other widgets, eg. a QWidget containing a QLineEdit.
first, i tried adding a layout to the container widget and adding sub-widgets to it, but the result was that the item didn't seem to be editable anymore at all (or the widget has hone somewhere / was zero-sized or whatever).
i tried overriding the setGeometry function for my subclasses but when the delegate calls setGeometry, allways the standard QWidget function is called.
i declared setGeometry as:Qt Code:
To copy to clipboard, switch view to plain text mode
If you use a completely custom widget for editing, you need to reimplement setModelData() and setEditorData() in the delegate. And probably you need to set a proper focus policy and maybe even a focus proxy. See docs for details.
i allready overloaded setModelData() and setEditorData(). editing works just fine - only the layout is messed up.
Can we see the code of the widget and its layouts?
here it is, the layout stuff has been commented out:
Qt Code:
{ public: { // //QVBoxLayout *p_pLayout = new QVBoxLayout(); //this->setLayout(p_pLayout); }; ~ItemEditor(void){}; }; class ItemLineEditor : public ItemEditor { private: QLineEdit *m_pLineEdit; public: { // without layout //using a layout doesn't work at all //m_pLineEdit = new QLineEdit(this); //this->layout()->addWidget(m_pLineEdit); } { return m_pLineEdit->text(); } { this->m_pLineEdit->setText(i_Data.toString()); } // gets never called virtual void setGeometry(const QRect& rect) { ItemEditor::setGeometry(rect); this->m_pLineEdit->setGeometry(rect); } };To copy to clipboard, switch view to plain text mode
as you may see, i'm doing this because i need a unified way of accessing the user input from different widgets (combobox, doublespinbox, lineedit etc.)
maximAL (10th December 2007)
1. setGeometry() is not virtual, so overriding it doesn't make much sense,
2. You never set the geometry of the line edit - you should either be using layouts or reimplement resizeEvent() and use setGeometry() to set the geometry of all child widgets
3. I don't really know what you mean about a unified way to initialize the contest, but maybe seeing how it is done for a widget mapper helps:
http://doc.trolltech.com/qq/qq21-dat...toofferchoices (what's important is the content of set*Data methods).
maximAL (10th December 2007)
Bookmarks