Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to word wrap a QTreeWidgetItem

Tags:

qt4

pyqt

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.

like image 247
japs Avatar asked Mar 03 '10 09:03

japs


People also ask

What is the process of word wrap?

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.

How do you implement word wrap?

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.

What is word wrap in notebook?

: 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.


1 Answers

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!!

like image 174
japs Avatar answered Sep 27 '22 17:09

japs