How to word wrap a QTreeWidgetItem

后端 未结 2 539
死守一世寂寞
死守一世寂寞 2021-01-04 11:14

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.

相关标签:
2条回答
  • 2021-01-04 11:27

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

    0 讨论(0)
  • 2021-01-04 11:30

    setWordWrap just causing wrapping around word-boundaries... it will NOT force anything on to a new line.

    What you are looking for is not possible with the default QTreeWidget. I suggest displaying text that is too long in an alternative way, such as mouse-over text or a separate label. TreeViews should not contain more then one line of text per item.

    0 讨论(0)
提交回复
热议问题