0
votes

I am having troubles setting column widths with a QTreeWidget. The code snippet is as follows:

categories = QTreeWidget(my_widget)
categories.setColumnCount(2)
categories.setHeaderLabels(['Objects', 'Count'])
categories.currentItemChanged.connect(categoriesChanged)
vbox.addWidget(categories)
categories.setColumnWidth(1,66)

It seems like the final line isn't doing as I expected. Whst i would like is for the rightmost column to be much narrower than the left column.

By dragging the seperator in the header, I can successfully drag the columns to give the desired relative widths, and then by inspecting the categories.columnWidth property, I can see that the widths have changed, but I cannot seem to explicitly set the column width programmatically.

Thankyou,

Stuart

1
Can you show an image of what you get and what you want to get?eyllanesc
@eyllanesc I am now away from my computer, so I cannot show an image, but what I have created is similar to this: i.stack.imgur.com/F0KW0.png but with each column being equal width, whereas I need a wider left column and narrower right column.Stuart Buckingham

1 Answers

1
votes

After asking around some more, I finally have the answer.

You can not set the width of the rightmost column because it is stretched to satisfy the minimum width of the width. Instead, the left column(s) can have their size set. I found that this causes the combined width of the two columns to exceed the width of the widget, and therefore a scrollbar appeared at the bottom of the widget. To get rid of this, the right column width can be set to a smaller width.

Hopefully someone else finds this useful.