I have a custom view delegate to right-align some text and I'm having a problem when the device (Nokia N900) is rotated. The problem seems to be that the QStyleOptionViewItem parameter in the delegate's paint function does not contain the correct rect to represent the size. When the device is rotated, all right-aligned text ends up outside the window and must be scrolled over to bee seen. If the window is opened after the device is first rotated, everything does however work as expected. It seems like the size of the QStyleOptionViewItem's rect member is not updated when the table and the window resizes. As if it is only updated and stored the first time the window is shown.
Is there a way that I may force the delegate/view to update the size of this rectangle corresponding to the new width/height after rotation? Upon rotation I've tried to call the view's resizeColumnsToContente, updateGeometry and reset()-functions as well as the model's reset() function without any effect.
The code in question is this:
If there are any other ways to right align some of the text using a delegate I would love to hear about those as wellCode:void DepartureListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyledItemDelegate::paint(painter, option, index); Departure *e = qVariantValue<Departure *>(index.data()); QFont font = option.font; QRect rect = option.rect; rect.adjust(10, 10, -20, -7); painter->save(); painter->drawText(rect, Qt::AlignTop | Qt::AlignLeft, e->lineNumber + " " + e->lineDestination); painter->drawText(rect, Qt::AlignTop | Qt::AlignRight, e->arrivalDifference + " min"); painter->setPen(option.palette.mid().color()); font.setPointSizeF(font.pointSizeF() * 0.70); painter->setFont(font); painter->drawText(rect, Qt::AlignBottom | Qt::AlignLeft, e->arrivalTime); painter->restore(); }![]()

Reply With Quote

