PDA

View Full Version : updateEditorGeometry() and height change



Lykurg
30th September 2008, 17:50
Hi,

in a sublassed QItemDelegate I create an editor which is higher than the normal item height (tested with QListWidget and QTreeVeiw). Therefore I also reimplement updateEditorGeometry() which updates the editor geometry to the adjusted size of my widget. But the problem is, that the other items don't moved down. So the editor hides the items below. How to move the positions of the other items?

Lykurg


myDelegate::myDelegate( QObject *_parent ) :
QItemDelegate( _parent )
{
tw = (QListWidget*) _parent;
}

myDelegate::~myDelegate()
{
}

QWidget * myDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &, const QModelIndex & ) const
{
editorWidget *ed = new editorWidget( parent );
ed->adjustSize();
return ed;
}

void myDelegate::updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const
{
QRect r = option.rect;
r.setX( 30 ); // just for showing the overlay
r.setSize( editor->sizeHint() );
editor->setGeometry( r );
}

wysota
1st October 2008, 21:08
Well... a short answer is you can't. A bit longer is to try to update the size hint of the item and emit a proper signal from the delegate.

An alternative is to make the editor a popup widget, like a combobox or QDateEdit.