I need to reduce the size of first column(the column with vertical headers)
How can I resize a vertical header of QTableView in PyQt4?
I have very large headers and small GUI block to show this table so, please help me!
I am able to resize all the columns but not able to figure out resizing the vertical headers?
I have tried many things like:
self.tableView.setColumnWidth(0, 30) // only able to change the data columns in table not headers
self.tableView.verticalHeader().setResizeMode(QHeaderView.Interactive) //Able to change the height of headers but not width of them
I want to make the headers which can be resized by the user and has no dependencies on any other parameters of the project like window size, size of other columns....
Can someone help me with this?
You can limit the size of the vertical header using setMaximWidth, and use setTextElideMode to adjust how the text is cropped.
However, there is no built-in method for making the vertical header width resizable by the user. So as a work-around, you could use the resize-event to adjust the width of the vertical header to a percentage of the total width. That way, resizing the window will also change the width of the vertical header.
Here is a demo script that implements all of that:
UPDATE:
I had a go at writing a custom header class that implements user resizing of the vertical header width. It almost works, but I cannot find a way to update the view properly whilst dragging with the mouse. Anyway, here is a demo of what I have so far in case anyone can see how to make it work: