0

テキストを 90 度の角度で表示したいセル (1 列、5 行) のスパンがあります。ジオメトリのサイズを変更する必要があることはわかっていますが、今のところ、テキストを表示することさえできません。真ん中の行では、サブクラス化された QItemDelegate::paint() 内でこれを行っています

QString data = "String";
painter->rotate( 90 );
painter->drawText( opt.rect, Qt::AlignLeft, data );

基本的に、この場合は何も印刷されません。他のいくつかの質問から、このようなコードにたどり着きました。何か不足していますか?

4

1 に答える 1

0

パターンは、コメントに投稿したリンクと同じです。これは多かれ少なかれこのように見えるはずです。サインを台無しにしたり、タイプミスをしたりする可能性があります。

#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();
}
于 2015-10-08T19:56:59.937 に答える