我有一组单元格(1列,5行),其中我希望以90度的角度显示文本。我知道我需要调整几何图形的大小,但现在我甚至不能显示文本。在中间一行,我在我的子类QItemDelegate::paint()中执行此操作。
QString data = "String";
painter->rotate( 90 );
painter->drawText( opt.rect, Qt::AlignLeft, data );基本上,在这种情况下,我没有打印任何内容。其他一些问题将我引向这样的代码。我是不是遗漏了什么?
发布于 2015-10-09 03:57:00
模式与我在评论中发布的链接相同。这应该或多或少看起来像这样。我可能弄错了一些标志或者打字错误。
#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();
}https://stackoverflow.com/questions/33023363
复制相似问题