PyQT5 sizing issue with QTableView and QGridLayout

40 views Asked by At

I built a GUI program that has outputs on single line tables, and I recently updated it using QGridLayout to make it dynamically adjust to different system scalings.

The issue I'm having is the pandas table I load into the QTableView widget seems to be expanding the row to take up a ridiculously large amount of space in the window:

Demonstration of Scaling issue

I have tried setting the minimum row height using setRowHeight( ... ) to a smaller value and setting setRowStretch to 0, but it doesn't do anything. Resizing the table object also has no effect.

Here is the code:

# Table Results
self.Table = QTableView()
__dfwa = pd.DataFrame()
__dfwa['# of Neighbours']                      = np.array([None])
__dfwa['Weighted Average Percent Removal [%]'] = np.array([None])
__modelwa                                      = pandasModel(__dfwa)
self.Table.setModel(__modelwa)
self.Table.horizontalHeader().setSectionResizeMode(0, self.Table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
self.vbox.addWidget(self.Table, 49,15,1,22)

Where self.vbox is called using:

self.vbox = QGridLayout()

I also know it isn't another object on this row causing issues because if the table is deleted, then the whole GUI rescales to its proper proportions.

I've tried:

self.Table.resize(375, 20)

and

self.vbox.setRowMinimumHeight(49,20)
self.vbox.setRowStretch(49,0)

I've changed up the values in the functions and it has no effect. If anyone has run into this issue before and found a solution it would be very helpful as I've been stuck on this for a while now. Thanks in advance!

CLARIFICATION

Since my original question was unclear, here is what I mean. This is HOW I WANT IT TO LOOK:

How I would like the GUI to look

This is HOW IT ACTUALLY LOOKS:

How the actual GUI Looks

Possible Solution

I think I've found an imperfect workaround for now, I've added this code:

for _i in range(__nRowsMain):
    if _i == 49:
        self.vbox.setRowStretch(_i, 1)
    self.vbox.setRowMinimumHeight(_i, __perH)
    self.vbox.setRowStretch(_i, 0)

Where __nRowsMain is the total number of rows in my grid, and __perH is an integer value I set the rest of the row heights. It's not perfect but it's better than nothing.

0

There are 0 answers