lundi 31 août 2015

QStyledItemDelegate createEditor() has wrong location for some items

I use a specialised QStyledItemDelegate to create a QLineEdit as editor in my QTreeView:

QWidget* MyStyledItemDelegate::createEditor(QWidget* parent, QStyleOptionViewItem const& option, QModelIndex const& index) const
{
  QLineEdit* lineEdit = new QLineEdit(parent);
  QStyleOptionViewItemV4 opt = option;
  initStyleOption(&opt, index);
  lineEdit->setFixedSize(opt.rect.width(), opt.rect.height());
  return lineEdit;
}

This creates a correct editor that has the correct size and location for most items. However, if the item has a checkbox (created with Qt::CheckStateRole), the line edit is slightly of in y-coordinate (around 2px) and of in x-coordinate (around the size of the checkbox). This covers other parts of the Treeview and does not look great.

Is there a way to circumvent this issue?

Aucun commentaire:

Enregistrer un commentaire