PDA

View Full Version : QTableView and QStyledItemDelegate Persistent Editor Issue



kev946
16th August 2019, 22:21
I have a QTableView and a QStyledItemDelegate derived class. I call tableView->setItemDelegateForColumn(0, new SpinBoxDelegate()) in the table constructor. When a row is added, I call tableView->openPersistentEditor(index). At this point I'd expect each cell to always show the SpinBox editor, but it only shows when the cell is clicked and enters into editing mode. Am I missing something?

kev946
21st August 2019, 22:53
I was able to get this working by doing something like:



void SpinBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
_spinBox->setGeometry(option.rect);
_spinBox->setValue(index.data().toInt());
QPixmap map = QPixmap::grabWidget(_spinBox);
painter->drawPixmap(option.rect.x(), option.rect.y(), map);
}

d_stranz
23rd August 2019, 23:39
@Linnda23: Use the "Thanks" button, please. It is a lot more effective than simply quoting a reply and adding a +1 and a broken image link.