Important: Please read the Qt Code of Conduct -

Item delegate sizeHint with style sheet

  • I'm using a subclassed QStyledItemDelegate to render html in a QTableView using a QTextDocument. I also have a stylesheet for my table that contains paddings and borders for each item. My delegate's sizeHint gets the QTextDocument's size similarly to QCommonStyle, but how do I adjust the size by the paddings to get the right total box size? QStyleSheetStyle uses QRenderRule to adjust the base size by paddings/margins/borders, but this information isn't part of the public API. As a result, my sizeHint is too small which can cause bleeding from one cell to the next when drawing. What is the right approach to get the total box size in my sizeHint?

  • Maybe I'm missing something but it's worth a try: if you copy the default implementation of QStyledItemDelegate::sizeHint (QStyledItemDelegatePrivate::widget(option) can trivially be replaced with option.widget) and just set opt.rect to the a rectangle with origin in 0,0 and size equal to your document size it should work.

  • @VRonin Thank you for your response. Unfortunately that won't help anything. My size hint returns exactly what the implementation of QStyledItemDelegate::sizeHint does in the case of no markup. However, with a style sheet that size is privately adjusted to account for style sheet margins, padding, and borders (see here). That information seems to be unavailable to manually adjust any subclassed sizeHint.

Log in to reply