Threading.Thread(target=self.table_size_watcher). Self.signal_table_size_nnect(self.adjust_table_column_width) Self.signal_table_size_changed = Signal() In the below example, the ratio of column widths are 1:1:2. I was not able to find an "out of the box" solution but I did the below:Ĭreate a thread which checks whether the size of the table has changed every 50 milliseconds and if it has, trigger a signal to a slot which updates the column widths based on the current table size. You also may need to fudge around with the width calculations a bit because of margins and padding between columns (like add a pixel or two to the calculated_width for each column to account for the cell border). A few columns, such as the or Shared columns, allow a column size of less than 130 ( allows a minimum of 65, while Shared allows 64), meanwhile other columns require a larger minimum column width (such as Rating at 138 pixels), but most are stuck at a 130 pixel minimum. You can set the resize mode to ResizeToContents, or if you want the user to be able to adjust the column width as needed, just call resizeColumnsToContents manually after making changes to the table items. tWidth(size.width() + total_width - calc_width) Total_width = ().size().width()įor i in range(()): Size = super(ResizeDelegate, self).sizeHint(option, index) Super(ResizeDelegate, self)._init_(*args, **kwargs) class ResizeDelegate(QStyledItemDelegate):ĭef _init_(self, table, stretch_column, *args, **kwargs): If you want to resize to contents and have automatic stretch, you'll need to choose which column is the "stretch" column. You can do this with QItemDelegates or QStyledItemDelegates. And when I press back button the column on the previous folder is also restored to the normal width. It seems that the initial column size is narrow, but when I change the folder, the file name column changes/restores to the one was set. Here's what happens with ResizeToContents Yosemite’s Finder without TotalFinder didn’t have this column size problem. Red arrows indicates what I'd like to have. The only thing that can be modified in the table is the last column, the user can enter a number in it. It would be better if there existed a setStretchFirstSection method, but unfortunately there does not seem to be one. tResizeMode(QHeaderView.ResizeToContents) Neither Interactive, Fixed, Stretch, ResizeToContents from the QHeaderView documentation seem to give me what I need (see second edit).Īny help would be appreciated, even if it is for Qt/C++ ! Thank you very much.ĮDIT : I found kind of a workaround but it's still not what I'm looking for : header = table.horizontalHeader() I've also tried table.horizontalHeader().setResizeMode(QHeaderView.ResizeToContents) thanks to Fabio's comment but it doesn't fill all the available space as needed. I've tried table.horizontalHeader().setResizeMode(QHeaderView.Stretch) after reading this question but it makes 3 columns of the same size. I'd like to have my table resize in order to adjust its size to the data, or at least to be able to set the column sizes as (say) 70/15/15 % of the available space. Let's say my table has 3 columns, but the data they contain is very different, like (for each row) a long sentence in the first column, then 3-digit numbers in the two last columns. I'm developing a computer application with PySide and I'm using the QTableWidget.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |