[Interest] ItemDelegate and word wrapping
abbapoh at gmail.com
Sat Feb 2 09:42:05 CET 2013
This hack has some disadvantages too. I made small investigation into a QCommonStyle and it's inherited styles to find solution for that particular feature in Qt.
Is it possible to add new values to QStyleOptionViewItemV2::ViewItemFeature? Something like ViewItemFeature::WrapAnywhere and ViewItemFeature::WrapAtWordBoundaryOrAnywhere ? Or this is an awful hack?
Better solution is to introduce QStyleOptionViewItemV5 with WordWrap property, but i'm not sure how views should use it. Should new "wordWrapMode" property be added to views (and should be "wordWrap" prop deprecated) or this feature can only be used in custom views?
Also, there's a problem in QCommonStylePrivate::viewItemSize method - it bounds text rect to icon rect, but normally text should take more place than the icon. If QListView::gridSize prop is set, it should be bounded to that grid size instead (and optionV5 should have gridSize prop too?). However, i don't know what should be the bound in case when no grid size is specified. Maybe pixel width of the longest word in the text (bad approximation, because it almost same as "word wrap").
So, should any patches be applied to Qt styles and if yes - how?
01.02.2013, в 18:11, Bache-Wiig Jens <Jens.Bache-Wiig at digia.com> написал(а):
On Feb 1, 2013, at 1:15 PM, André Somers <andre at familiesomers.nl> wrote:
> I fully agree with Andre that the API should have more flexibility built into it. If only as a way to tell it which parta to draw and which to ignore.
> I would however advice against hardcoding style names. I think the simplest way right now would be to reimplement displayText to return an empty string, call the base implementation in paint(), fetch the DisplayRole and draw it yourself. At least if you are ok with keeping the icon decoration as it is. Otherwise use the model hack that Andre suggested.
More information about the Interest