Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Item delegate sizeHint with style sheet

Item delegate sizeHint with style sheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 567 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rockg
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    1
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      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.

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • R Offline
        R Offline
        rockg
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved