[PyQt] Possible bug or change in PyQt5.10.1, width changing when adding item to QTreeWidget

THOMAS EDVARDSEN THOMAS.EDVARDSEN at hotmail.com
Tue Jun 26 21:36:30 BST 2018


Hello,


I encountered an issue with PyQt 5.10.1, where if i have a QTreeWidget with sorting enabled, adding a QTreeWidgetItem causes the width to double. (Or at least increase)

This only happens in PyQt 5.10.1. (Tested 5.9 and 5.10, where this does not happen). If i disable the sorting, it will not increase the width of the widget. I have not been able to install 5.11 because i can't load the site, nor is it on pypi yet, so i don't know if it's fixed in that version. Provided is a minimal example to prove my issue:


##############

from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QApplication
from PyQt5.QtCore import pyqtSignal


class Tree(QTreeWidget):
    sendItem = pyqtSignal(QTreeWidgetItem)

    def __init__(self):
        super().__init__(parent=None)

        self.setSortingEnabled(True)  # Remove or set to False to get pore 5.10.1 behaviour

        item = QTreeWidgetItem(self)
        item.setText(0, 'test test test test test test test test test test test test testtesttesttest')

        self.itemClicked.connect(self.add_item)

    def add_item(self, _, __):
        item = QTreeWidgetItem(self)
        item.setText(0, 'broken')


if __name__ == '__main__':
    app = QApplication([])
    a = Tree()
    a.show()
    app.exec_()


######################


Simply run and click the item with text, and it will add another item to the tree. If sorting is enabled, width will change, if not, it won't. In earlier versions, width is unchanged regardless of sorting.

Anyone know, can test, or happen to know possible workaround if this is a problem in 5.11 too?


My OS is windows 10, and python version is 3.6.5 64-bit.



Thomas.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180626/e1c6770e/attachment-0001.html>


More information about the PyQt mailing list