{
if(index.parent().isValid())
{
QString text
= index.
model()->data
(index, Qt
::DisplayRole).
toString();
myOption.rect.adjust(0,0,500,0);
myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
QApplication::style()->drawItemText
( painter, myOption.
rect , myOption.
displayAlignment,
QApplication::palette(),
true,text
);
}
else
{
QStyledItemDelegate::paint(painter, option, index);
}
}
void ColumnDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if(index.parent().isValid())
{
QString text = index.model()->data(index, Qt::DisplayRole).toString();
QStyleOptionViewItem myOption = option;
myOption.rect.adjust(0,0,500,0);
myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
QApplication::style()->drawItemText ( painter, myOption.rect , myOption.displayAlignment, QApplication::palette(), true,text );
}
else
{
QStyledItemDelegate::paint(painter, option, index);
}
}
To copy to clipboard, switch view to plain text mode
this solve my previous problem, but I meet another problem, when I adjust second column width it will hide the content of child item. how to solve this problem, see the attachment.
Bookmarks