I have to populate a QTreeWidget with items (or children of items) that may happen to be too long to fit in a single line, so I'm looking for a way to word wrap them.
I thought
myQTreeWidget.setWordWrap(True)
(done via QtDesigner4) would have done the job, but that doesn't seem to be the case.
I don't know if it is relevant, but the tree is enveloped in a splitter frame, so the wrapping should be somehow dynamic to allow resizing of the splitter.
Any ideas? I use PyQt4, but hints in any language/binding would be appreciated.
In computing, word wrapping is a process by which a word which comes at the end of a line is automatically moved onto a new line in order to keep the text within the margins.
Go to Picture Format or Shape Format and select Arrange > Wrap Text. If the window is wide enough, Word displays Wrap Text directly on the Picture Format tab. Choose the wrapping options that you want to apply. For example, In Line with Text, Top and Bottom, and Behind Text.
: a word processing feature that automatically transfers a word for which there is insufficient space from the end of one line of text to the beginning of the next.
I successfully found a workaround: i envelope a QLabel in the WidgetItem, setting the QLabel to have word wrap capabilities.
item = QTreeWidgetItem()
label = QLabel('long text here')
label.setWordWrap(True)
MyTree.addTopLevelItem(item)
MyTree.setItemWidget(item, 0, label)
the behaviour is exactly the one desired!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With