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. Determining correct row height for multi-line QTableWidgetItem?
Forum Updated to NodeBB v4.3 + New Features

Determining correct row height for multi-line QTableWidgetItem?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 447 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.
  • P Offline
    P Offline
    Publicnamer
    wrote on last edited by Publicnamer
    #1

    I've got a table cell that is displaying multi-line text that wraps and can have newlines, displaying any number of lines as needed based on the table's width.

    Up to now I've been using my own code to determine the ideal height for a row, because I have found that it is much more accurate than resizeRowToContents, which seems to be off by a factor of 4.

    My code is based on QFontMetrics's boundingRect. However my code is not as accurate as I want, either. There seem to be internal margins to the QTableWidgetItem that I'm not yet taking into account.

    So, what is the best way to determine the ideal height for a row that has multiple lines?
    Why is resizeRowsToContents so inaccurate?

    Thanks.

    P 1 Reply Last reply
    0
    • P Publicnamer

      I've got a table cell that is displaying multi-line text that wraps and can have newlines, displaying any number of lines as needed based on the table's width.

      Up to now I've been using my own code to determine the ideal height for a row, because I have found that it is much more accurate than resizeRowToContents, which seems to be off by a factor of 4.

      My code is based on QFontMetrics's boundingRect. However my code is not as accurate as I want, either. There seem to be internal margins to the QTableWidgetItem that I'm not yet taking into account.

      So, what is the best way to determine the ideal height for a row that has multiple lines?
      Why is resizeRowsToContents so inaccurate?

      Thanks.

      P Offline
      P Offline
      Publicnamer
      wrote on last edited by
      #2

      I see there's been no response. Is this a part of Qt that is just known to be buggy? Maybe no one wants to address the bug?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        Perhaps there is no response because there is nothing in your original post to let people to demonstrate the claimed problem or what you have actually done.

        You make assertions that resizeRowToContents computed row height is off by a factor of four: bigger or smaller is unknown, but this seems very unlikely to have gone unnoticed. Then you tell us your own code is fails to meet your expectations in some unspecified way. We see neither the problem nor your code so it is very difficult to help you.

        Try posting a small, self-contained example that demonstrates the problem with screen shots, then you might have a better response.

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

          Can you show us how you determine the size? the concept you are describing seems correct so it shouldn't take much to address the spacing/padding issue

          "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

          P 1 Reply Last reply
          0
          • VRoninV VRonin

            Can you show us how you determine the size? the concept you are describing seems correct so it shouldn't take much to address the spacing/padding issue

            P Offline
            P Offline
            Publicnamer
            wrote on last edited by
            #5

            @VRonin
            This is how I programmatically determine the row height.

                    int presumed_internal_padding = 12;
                    int widgetWidth = table->width() - 2 * presumed_internal_padding;
                    QFont font("Helvetica", fontsize, false, false);
                    QFontMetrics metrics(font);
                    QRect rect = metrics.boundingRect(0, 0, widgetWidth, INT_MAX, Qt::TextWordWrap, theText, 0, NULL);
                    return rect.height();
            
            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