模式与我在评论中发布的链接相同。这应该看起来或多或少像这样。我可能搞砸了一些标志或做一些错字。
#include "customitemdelegate.h"
#include <QPainter>
CustomItemDelegate::CustomItemDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
void CustomItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem newOption(option);
QTransform transform(QTransform::fromTranslate(-option.rect.center().x(),
-option.rect.center().y()));
transform.rotate(90);
painter->setTransform(transform);
transform=transform.inverted();
newOption.rect=transform.mapRect(newOption.rect);
QItemDelegate::paint(painter, newOption, index);
// restore state of painter
painter->setTransform(transform);
}
QSize CustomItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return QItemDelegate::sizeHint(option, index).transposed();
}