mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Объединенные ячейки списка
This commit is contained in:
41
InstructorsAndTrainees/tasks/customdelegate.cpp
Normal file
41
InstructorsAndTrainees/tasks/customdelegate.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "customdelegate.h"
|
||||
|
||||
CustomDelegate::CustomDelegate(QObject *parent):
|
||||
QItemDelegate(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CustomDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
bool mergeCell = index.data(UserRole_MergeCell).toBool();
|
||||
|
||||
if (mergeCell && index.column() == 0)
|
||||
{
|
||||
QModelIndex nextColumnIndex = index.siblingAtColumn(index.column() + 1);
|
||||
if (!nextColumnIndex.isValid())
|
||||
{
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
return;
|
||||
}
|
||||
|
||||
QRect mergedRect(option.rect.x(),
|
||||
option.rect.y(),
|
||||
option.rect.width() * 2,
|
||||
option.rect.height());
|
||||
|
||||
painter->save();
|
||||
painter->setClipRect(mergedRect);
|
||||
drawBackground(painter, option, index);
|
||||
drawDisplay(painter, option, mergedRect, index.data(Qt::DisplayRole).toString());
|
||||
|
||||
painter->restore();
|
||||
} else {
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
}
|
||||
|
||||
QSize CustomDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return QItemDelegate::sizeHint(option, index);
|
||||
}
|
||||
Reference in New Issue
Block a user