2

MainWindow

Hi, I have created MainWindow as shown above. I want to expand the first widget (plots) as much as possible so that the other two widgets fit content (or actually, I want to remove white empty space below tables). I don't know how to do that.

Currently, both table vertical header size policy is set to FitToContent.

Also, it needs to be dynamic so if I add a new row to the table, a new row should be visible (table will be larger).

I hope I'm clear enough, and also hope there is no need for runnable code.

Hamada
  • 1,836
  • 3
  • 13
  • 27
Brat Karamazov
  • 141
  • 1
  • 11
  • Does this answer your question? [Columns auto-resize to size of QTableView](https://stackoverflow.com/questions/18293403/columns-auto-resize-to-size-of-qtableview) – Ingo Mi Jun 19 '20 at 22:21
  • @Ivanovic nope that is not it.I need to reduce height, not strech existing rows. Couldn't open link. – Brat Karamazov Jun 23 '20 at 06:21

1 Answers1

5

Ok, I figure it out.

Reimplementing the resizeEvent will do the trick.

    def resizeEvent(self, event):
        super(Table, self).resizeEvent(event)
        height = self.horizontalHeader().height()
        for row in range(self.model().rowCount()):
            height += self.rowHeight(row)

        if self.horizontalScrollBar().isVisible():
            height += self.horizontalScrollBar().height()
        self.setMaximumHeight(height + 2)

I'm changing the height of QTableView. I'm including height of horizontal header + height of all rows + height of horizontalScrollBar if it is visible.

Brat Karamazov
  • 141
  • 1
  • 11