<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Well, you are setting a Fixed horizontal policy on the tables, which means that they cannot be "shrunk" even if they could, and they will then use their default size hint (which is usually 256x192 for widgets that inherit from QAbstractScrollArea, so, all item views).<div><br></div><div>Assuming that the table contents are not going to change, the solution is to set a fixed width based on the contents, and the width is computed by the sum of:</div><div><br></div><div>- the horizontal header length();</div><div>- the vertical header size hint width;</div><div>- the vertical scroll bar size hint width;<br></div><div>- the frame width of the view, multiplied by two (left and right side);</div><div><br></div><div><div><font face="monospace">            width = (</font></div><div><font face="monospace">                h_header.length() + </font></div><div><font face="monospace">                table.verticalHeader().sizeHint().width() + </font></div><div><font face="monospace">                table.verticalScrollBar().sizeHint().width() + </font></div><div><font face="monospace">                table.frameWidth() * 2</font></div><div><font face="monospace">            )</font></div><div><font face="monospace">            table.setFixedWidth(width)</font></div></div><div><br></div><div>Note that the above will only work *after* setting the header labels *and* filling the whole table.</div><div><br>A better implementation would use a subclass of the table widget and update the fixed width whenever the model changes (row/column amount, data changed).</div><div><br>On an unrelated matter, please consider that you should **NEVER** modify the files generated by pyuic, and you should instead implement the logic (including the dynamic table creation) in a separate script, and then use a subclass of QMainWindow (or the QWidget subclass used in Designer, like QDialog for instance) *and* the imported form class, as suggested for the multiple inheritance method in the official PyQt guidelines about using Designer: <a href="https://www.riverbankcomputing.com/static/Docs/PyQt5/designer.html">https://www.riverbankcomputing.com/static/Docs/PyQt5/designer.html</a></div><div><br></div><div>Maurizio</div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno ven 27 ago 2021 alle ore 14:27 paparucino <<a href="mailto:paparucino@gmail.com">paparucino@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello, I'm new to the list and besides apologizing for any errors please <br>
correct me so I can improve.<br>
My problem is that I can't delete the white space after the table with <br>
the data. Pls look at the attached drawing.<br>
The script I use is the one below.<br>
I noticed that whatever the value used for the various sizes (apart from <br>
MainWindow.resize (900, 650)) none of them affect the size of both the <br>
internal table and its container. I guess they are default values and I <br>
am not able to change them.<br>
Any help is appreciated.<br>
<br>
===================<br>
<br>
import calendar<br>
from functions import *<br>
from PyQt5 import QtCore, QtGui, QtWidgets<br>
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton<br>
<br>
<br>
class SpecialStyledItemDelegate(QtWidgets.QStyledItemDelegate):<br>
     def __init__(self, parent=None):<br>
         super().__init__(parent)<br>
         self._values = dict()<br>
<br>
     def add_text(self, text, row):<br>
         self._values[row] = text<br>
<br>
     def initStyleOption(self, option, index):<br>
         super().initStyleOption(option, index)<br>
         row = index.row()<br>
         if row in self._values:<br>
             option.text = self._values[row]<br>
             option.displayAlignment = QtCore.Qt.AlignCenter<br>
<br>
<br>
class Ui_MainWindow(QMainWindow):<br>
     def __init__(self):<br>
         super().__init__()<br>
         self.setupUi(self)<br>
<br>
     def setupUi(self, MainWindow):<br>
<br>
         MainWindow.setObjectName("MainWindow")<br>
         MainWindow.resize(900, 650)<br>
         self.centralwidget = QtWidgets.QWidget(MainWindow)<br>
         self.centralwidget.setObjectName("centralwidget")<br>
<br>
         self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget)<br>
         self.horizontalLayout.setObjectName("horizontalLayout")<br>
<br>
         self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)<br>
         self.scrollArea.setWidgetResizable(True)<br>
         self.scrollArea.setObjectName("scrollArea")<br>
         self.scrollAreaWidgetContents = QtWidgets.QWidget()<br>
         #self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, <br>
0, 0))<br>
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")<br>
         self.layout = QtWidgets.QHBoxLayout(self.scrollAreaWidgetContents)<br>
         #self.layout.setContentsMargins(0, 0, 0, 0)<br>
         self.layout.setObjectName("layout")<br>
<br>
<br>
         conn = x<br>
         cursor = conn.cursor(buffered=True, dictionary=True)<br>
         mese = '9'<br>
         anno = '2021'<br>
<br>
         self.alphamese = Functions.convert_number_month[mese]<br>
         daysinmonth = calendar.monthrange(int(anno), int(mese))[1]<br>
         query = "SELECT * FROM `alldata` WHERE anno = '%s' AND mese = <br>
'%s'" % (anno, mese)<br>
         cursor.execute(query)<br>
         search = cursor.fetchall()<br>
         zz = 'table_'<br>
         cc = 0<br>
         for row in search:<br>
             self.vol_name = row['nome']<br>
             self.c_query = "SELECT grp FROM volontari WHERE cognome = <br>
'%s'" % (self.vol_name)<br>
             cursor.execute(self.c_query)<br>
             self.grp = cursor.fetchall()<br>
             for val in self.grp:<br>
                 table ='zz%s'%(str(cc))<br>
                 cc = cc+1<br>
                 self.group = val['grp']<br>
                 if self.group == 'C':<br>
<br>
                     table = QTableWidget(self.scrollAreaWidgetContents)<br>
                     table.setGeometry(QtCore.QRect(0, 5, 150, 597))<br>
                     sizePolicy = <br>
QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, <br>
QtWidgets.QSizePolicy.Expanding)<br>
                     #sizePolicy.setHorizontalStretch(50)<br>
                     #sizePolicy.setVerticalStretch(50)<br>
#sizePolicy.setHeightForWidth(table.sizePolicy().hasHeightForWidth())<br>
                     table.setSizePolicy(sizePolicy)<br>
                     table.setObjectName("StripTable")<br>
                     table.setRowCount(33)<br>
                     table.setColumnCount(3)<br>
<br>
                     self.special_delegate = SpecialStyledItemDelegate()<br>
                     table.setItemDelegate(self.special_delegate)<br>
<br>
                     h_header = table.horizontalHeader()<br>
                     h_header.hide()<br>
                     for i in range(h_header.count() - 1):<br>
                         h_header.setSectionResizeMode(i, <br>
QtWidgets.QHeaderView.ResizeToContents)<br>
                     h_header.setSectionResizeMode(2, <br>
QtWidgets.QHeaderView.Fixed)<br>
                     v_header = table.verticalHeader()<br>
                     v_header.hide()<br>
                     v_header.setDefaultSectionSize(17)<br>
<br>
                     table.setSpan(1, 0, 1, 3)<br>
                     table.setSpan(0, 0, 1, 3)<br>
<br>
                     zz = 1<br>
                     self.m_query = "SELECT * FROM `alldata` WHERE anno <br>
= '%s' AND mese = '%s' AND nome = '%s'" % (<br>
                     anno, mese, self.vol_name)<br>
                     cursor.execute(self.m_query)<br>
                     result = cursor.fetchall()<br>
                     self.special_delegate.add_text(self.vol_name, 0)<br>
                     self.special_delegate.add_text(self.alphamese, 1)<br>
<br>
                     #daysinmonth = 30<br>
                 while zz <= daysinmonth:<br>
                     for inrow in result:<br>
                         ##<br>
                         # Writes data in cell tables<br>
                         ##<br>
                         day = 'd' + str(zz)<br>
                         self.value = inrow[day]<br>
                         a_date = datetime.date(int(anno), int(mese), zz)<br>
                         self.dow = a_date.strftime("%a")<br>
                         self.dow = Functions.convert_en_it[self.dow]<br>
                         if (self.dow == 'Sun' or self.dow == 'Sat') and (<br>
                                 self.value == 'P' or self.value == 'D' <br>
or self.value == 'F' or self.value == 'B'):<br>
                             self.value = Functions.eva_mp1[self.value]<br>
                         else:<br>
                             self.value = Functions.eva_mp[self.value]<br>
                         table.setItem(zz + 1, 0, <br>
QtWidgets.QTableWidgetItem(str(zz)))<br>
                         table.setItem(zz + 1, 1, <br>
QtWidgets.QTableWidgetItem(self.dow))<br>
                         item = QtWidgets.QTableWidgetItem(self.value)<br>
item.setTextAlignment(QtCore.Qt.AlignCenter)<br>
                         table.setItem(zz + 1, 2, item)<br>
                         zz += 1<br>
             self.layout.addWidget(table)<br>
<br>
self.scrollArea.setWidget(self.scrollAreaWidgetContents)<br>
             self.horizontalLayout.addWidget(self.scrollArea)<br>
             MainWindow.setCentralWidget(self.centralwidget)<br>
<br>
             self.retranslateUi(MainWindow)<br>
             QtCore.QMetaObject.connectSlotsByName(MainWindow)<br>
<br>
     def retranslateUi(self, MainWindow):<br>
         _translate = QtCore.QCoreApplication.translate<br>
         MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))<br>
<br>
<br>
<br>
<br>
     def show_new_window(self):<br>
         print('Printato')<br>
         pass<br>
<br>
app = QApplication(sys.argv)<br>
<br>
window = Ui_MainWindow()<br>
window.show()<br>
<br>
app.exec()<br>
<br>
<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>