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. how to make the text wrap automatically in the qtablewidgetitem?
Forum Updated to NodeBB v4.3 + New Features

how to make the text wrap automatically in the qtablewidgetitem?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 404 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.
  • nicker playerN Offline
    nicker playerN Offline
    nicker player
    wrote on last edited by
    #1

    I found that the setWordWrap couldnt work when using the qtablewidgetitem.caused the alphabet .
    some one use the ItemDelegate class to make it right.but it looks very ugly.so is there any easier way that could wrap the text automatically ?for using adding en extra qlabel object into the widgetitem or something else?
    if (index.column() == 0)
    {
    textOption.setAlignment(Qt::AlignCenter);
    }
    else
    {
    textOption.setAlignment(Qt::AlignLeft| Qt::AlignVCenter);
    }
    textOption.setWrapMode(QTextOption::WrapAnywhere);
    doc.setDefaultTextOption(textOption);

    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      Please format your code, using the </> format tags.
      I also don't understand what you mean by

      caused the alphabet

      Please elaborate in a more understandable way, what the problem is. Maybe include a screenshot.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • nicker playerN Offline
        nicker playerN Offline
        nicker player
        wrote on last edited by
        #3

        the chinese articles could be wrapped correctlly .but not for the english and the long alphabet paragraph.its my poor english.sorry for that.
        image.png

        1 Reply Last reply
        0
        • Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #4

          I still don’t understand what the problem is. The widget item seems large enough for the text. Maybe show your code and draw a picture of the outcome you expect.

          Software Engineer
          The Qt Company, Oslo

          nicker playerN 1 Reply Last reply
          0
          • Axel SpoerlA Axel Spoerl

            I still don’t understand what the problem is. The widget item seems large enough for the text. Maybe show your code and draw a picture of the outcome you expect.

            nicker playerN Offline
            nicker playerN Offline
            nicker player
            wrote on last edited by
            #5

            @Axel-Spoerl
            fdd86809-1634-4131-b5af-a2ef27600470-image.png
            the above one is what i wanted.
            and the below one is the one in the fact.
            I just want to wrap the alphabet word .but unforunatelly ,it didnt work.

            JonBJ 1 Reply Last reply
            0
            • nicker playerN nicker player

              @Axel-Spoerl
              fdd86809-1634-4131-b5af-a2ef27600470-image.png
              the above one is what i wanted.
              and the below one is the one in the fact.
              I just want to wrap the alphabet word .but unforunatelly ,it didnt work.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @nicker-player
              The hyphen character (-) is often where word breaking occurs in English. On the other hand the underscore character (_) is treated a s part of a "word" and is not where wrapping gets chosen to occur.

              If QTextOption::WrapAnywhere does not work try WrapAtWordBoundaryOrAnywhere just in case that works better. I don't know what to suggest if none of these work.

              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