Код: Выделить всё
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
const QRect &r = option.rect;
painter->setPen(Qt::red);
CellGeometry cellAvatar;
cellAvatar.x1y1 = QPoint(0, 0);
cellAvatar.x2y2 = QPoint(option.rect.width(), 0);
painter->drawLine(0, 0, option.rect.width(), 0);
painter->drawLine(option.rect.width(), 0, option.rect.width()-1, option.rect.height()-1);
painter->drawLine(option.rect.width()-1, option.rect.height()-1, 0, option.rect.height()-1);
painter->drawLine(0, option.rect.height()-1, 0, 0);
painter->setPen(Qt::gray);
double halfWidth = option.rect.width()/2.00;
double halfHeight = (option.rect.height())/2.00;
double cell = (option.rect.width())/5.00;
painter->drawLine(cell, 0, cell, option.rect.height()-1); //avatar - cell 1
painter->drawLine(cell, halfHeight, option.rect.width(), halfHeight); //half main cell
painter->drawLine(cell*2, 0, cell*2, halfHeight); //cell 2
painter->drawLine(cell*3, 0, cell*3, halfHeight); //cell 3
painter->drawLine(cell*4, 0, cell*4, halfHeight); //cell 4
painter->drawLine(cell*5, 0, cell*5, halfHeight); //cell 5
}
Код: Выделить всё
QWidget *Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
qInfo()
Далее я вставляю объекты qlineedit в ячейки этой сетки, используя пользовательский виджет, как показано ниже < /p>
UserEditorDelegateWidget::UserEditorDelegateWidget(QWidget *parent): QWidget{parent, Qt::Widget}
{
this->setObjectName(QString("UserEditorDelegateWidget"));
{
nameLabel = new QLineEdit(this);
nameLabel->setObjectName("nameLabel");
nameLabel->setText("name");
// nameLabel->setGeometry(p1.rx(), p1.ry(), p2.rx(), p2.ry());
nameLabel->setGeometry(96, 0, 96, 28);
surnameLabel = new QLineEdit(this);
surnameLabel->setObjectName("surnameLabel");
surnameLabel->setText("surname");
surnameLabel->setGeometry(192, 0, 96, 28);
}
{
description = new QLineEdit(this);
description->setObjectName("description");
description->setText("very very long description");
description->setGeometry(96, 28, 384, 27);
}
}
и в теории, за исключением Prome, за исключением Prome. /> Редактор должен только собирать данные (CommercataTa) и Close (owlodeDitor), когда пользователь щелкает вне всего экземпляра редактора (то есть за пределами виджета userEditordElegateWidget), а не при переключении между полями редактора. За пределами этого.>
Подробнее здесь: https://stackoverflow.com/questions/797 ... ditemdeleg