PDA

View Full Version : QTreeWidget/QListWidget: Edit gives QLineEdit too little on the height



Alundra
30th March 2017, 22:15
Hi,
Using QTreeWidget or QListWidget I have too little height when I edit items, it's surely a common issue, giving the rename hard to do.
What is the best way to solve this issue ? Because set the size manually is maybe an option but Qt has something automatic to solve that ?
Thanks

Santosh Reddy
31st March 2017, 08:11
No automatic resize while editing, have to do it explicitly.

Alundra
31st March 2017, 13:24
Apparently the issue which cause this little edit line edit is because I use padding in QLineEdit in the stylesheet :


QLineEdit
{
...
padding: 2px;
}

Looks like a bug from Qt to not compute the size correctly from QLineEdit.
Where is the best place to set the size manually or maybe possible to create the editor QLineEdit widget manually with a lookup on the actual style of QLineEdit ?
I tried to change the sizeHint of the item in the QStyledItemDelegate but I only got bigger item, the editor widget is not resized.

EDIT:
Here the hack found to avoid the Qt issue :


virtual void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const override
{
// Init the item option.
QStyleOptionViewItem itemOption = option;
initStyleOption( &itemOption, index );

// Move the rect top value to avoid the height issue, 1px of padding on the top and bottom.
QRect Geom = QApplication::style()->subElementRect( QStyle::SE_ItemViewItemText, &itemOption, editor );
Geom.setTop( Geom.top() - 1 );

// Set the geometry.
editor->setGeometry( Geom );
}