QTableWidget - Column and row constraints

34 views Asked by At

I have many tables with this specifications:

  1. Number of rows 0 - ?
  2. Number of columns 3 - 12+
  3. In most columns i have only text, in many cases the last column is filled with setCellWidget (a QFrame with one or two or three buttons)

I want:

  1. Manage to columns-width, row-height at first use
  2. Constraint the resizing at run-time (column-width, row-height) depending of the cell data.

For the first:

  • I use setColumnWidth for every column to set the column width. This is not standard because it's depending on the screen size. For this purpose i may use a) resizeColumnToContents(int) or b) resizeColumnsToContents(). For the row height because the QFrame height is depending on the QPushButton size I use this:
counter = 0
for row in self.results:
    row_height = self.main_self.ui_sound_file_search_window.table.rowHeight(counter)
    self.main_self.ui_sound_file_search i_window.table.setRowHeight(counter,row_height+60)
    counter = counter + 1           

For the second I didn't something.

I can say that when I column is extremely resized then the text in QPushButton is cropped as you can see in the bellow image:

enter image description here

I use a Custom Style, but that's not the point of this question.

So what I really want is to make a QTableWidget which will have correct row-column sizes and will have constraints in column-resize, row-resize at run time by the user. This constraint will also be for horizontal header section items.

If I need to provide a minimal reproducible example, please also tell me what will be. For example a filled with data QTableWidget with no style (qss)?

0

There are 0 answers