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. Calculating sizeHint height for CustomDelegate with WrapAtWordBoundaryOrAnywhere Text
Forum Updated to NodeBB v4.3 + New Features

Calculating sizeHint height for CustomDelegate with WrapAtWordBoundaryOrAnywhere Text

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.5k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    Nosf
    wrote on last edited by
    #1

    Hey,

    How do you calculate the required sizeHint for an item where you need to paint a string with QTextOption flags such as WrapAtWordBoundaryOrAnywhere

    I cant use fontMetrics since i do not know where exactly the text is going to be cut to the next line.

    I tried using QTextDocument and setting the width i need and Getting the size out of it to calculate required height.

    But this has some strange behaviour when scrolling through the view where it does not seem to paint the item if its only partially visible.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      In a similar case, I used QTextDocument in the way you describe: set the width, and get out the height. I don't see why your sizeHint implementation would influence your rendering though?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nosf
        wrote on last edited by
        #3

        Yeh Andre thats what is puzzling me too. but ill debug it further if that is the way you guys would approach it too.

        It seems for some reason that items with multiple lines only half the lines get painted until the entire item is visible. It was not like sizeHint returned incorrect values though cos the item had the correct size. It was just blank at the bottom until i scrolled to get full item visible and it paints itself correctly.

        In the paintEvent i did use painter->drawText with textoption flag than use QTextDocument drawContents to not have to recreate QTextDocument inside it again but maybe thats having some strange outcomes. will check further tomorrow and update.

        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