how to make the text wrap automatically in the qtablewidgetitem?
-
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); -
Please format your code, using the </> format tags.
I also don't understand what you mean bycaused the alphabet
Please elaborate in a more understandable way, what the problem is. Maybe include a screenshot.
-
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 -
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.
-
@Axel-Spoerl
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. -
@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 tryWrapAtWordBoundaryOrAnywhere
just in case that works better. I don't know what to suggest if none of these work.