<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno gio 9 set 2021 alle ore 14:02 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">[...]<br>That link only shows instructions on how to prepare a good ssce but I <br>don't see any references to a mailing list</blockquote></div></div><div dir="ltr"><br></div><div>What Florian meant was that you should use the instructions on that website and then post to *this* mailing list.</div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno mer 8 set 2021 alle ore 16:47 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">
<div>
<p>I never edit the ui file. I keep it as a base and eventually I
create many .py files depending on how the debug goes. I know that
it is confusing and that I fill the dir with files but sometimes I
start from an idea and as everything evolves I can change my mind
and therefore I have a base plus a certain series of more or less
functional back ups<br></p></div></blockquote><div>Creating multiple UI files for the same interface is not an issue, as long as it's only done for UX purposes (aesthetic or design).</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
The example is perfect, but if I don't have an entry point for my
tables in the ui-> py file, I don't know where to start. I
created a ui file with scrollArea containing a number of tables,
transformed it into py, I "analyzed the code, I deleted all the
tables by inserting mine, with the necessary changes. Result: I get
what I expect. Then the problems begin.<br></div></blockquote><div><br></div><div>And that's an important hint, because it means that the whole concept begins with the wrong premise. If you have to dynamically create tables, those tables should *not* exist in the first place.<br><br></div><div>The UI should be like a "dough" for a cake, like those you buy in a store.</div><div>It has been made using basic ingredients, like eggs, flour, yeast and milk.<br>Then you can add anything you want, fruit, chocolate, nutella, etc.</div><div>But if you want to make a cake using wholemeal flour or lactose-free milk, you cannot remove them from that dough.</div><div>And if you want to create a "convenience dough" for a cake that could possibly have normal milk or lactose-free milk, then you have to create a basic dough that has **no** milk at all.</div><div></div></div><div dir="ltr"><br></div>I've prepared a basic example of what you might want to achieve. There's a basic QMainWindow with an *empty* scroll area (but an existing layout), and the code that allows you to create as many tables as you want.</div><div dir="ltr"><br></div><div dir="ltr">UI code (tables.ui):</div><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr"><font face="monospace"><?xml version="1.0" encoding="UTF-8"?></font></div><div dir="ltr"><font face="monospace"><ui version="4.0"></font></div><div dir="ltr"><font face="monospace"> <class>MainWindow</class></font></div><div dir="ltr"><font face="monospace"> <widget class="QMainWindow" name="MainWindow"></font></div><div dir="ltr"><font face="monospace"> <property name="windowTitle"></font></div><div dir="ltr"><font face="monospace"> <string>MainWindow</string></font></div><div dir="ltr"><font face="monospace"> </property></font></div><div dir="ltr"><font face="monospace"> <widget class="QWidget" name="centralwidget"></font></div><div dir="ltr"><font face="monospace"> <layout class="QVBoxLayout" name="verticalLayout"></font></div><div dir="ltr"><font face="monospace"> <item></font></div><div dir="ltr"><font face="monospace"> <layout class="QHBoxLayout" name="horizontalLayout_2"></font></div><div dir="ltr"><font face="monospace"> <item></font></div><div dir="ltr"><font face="monospace"> <widget class="QPushButton" name="addTableButton"></font></div><div dir="ltr"><font face="monospace"> <property name="text"></font></div><div dir="ltr"><font face="monospace"> <string>Add table</string></font></div><div dir="ltr"><font face="monospace"> </property></font></div><div dir="ltr"><font face="monospace"> </widget></font></div><div dir="ltr"><font face="monospace"> </item></font></div><div dir="ltr"><font face="monospace"> <item></font></div><div dir="ltr"><font face="monospace"> <spacer name="horizontalSpacer"></font></div><div dir="ltr"><font face="monospace"> <property name="orientation"></font></div><div dir="ltr"><font face="monospace"> <enum>Qt::Horizontal</enum></font></div><div dir="ltr"><font face="monospace"> </property></font></div><div dir="ltr"><font face="monospace"> <property name="sizeHint" stdset="0"></font></div><div dir="ltr"><font face="monospace"> <size></font></div><div dir="ltr"><font face="monospace"> <width>40</width></font></div><div dir="ltr"><font face="monospace"> <height>20</height></font></div><div dir="ltr"><font face="monospace"> </size></font></div><div dir="ltr"><font face="monospace"> </property></font></div><div dir="ltr"><font face="monospace"> </spacer></font></div><div dir="ltr"><font face="monospace"> </item></font></div><div dir="ltr"><font face="monospace"> </layout></font></div><div dir="ltr"><font face="monospace"> </item></font></div><div dir="ltr"><font face="monospace"> <item></font></div><div dir="ltr"><font face="monospace"> <widget class="QScrollArea" name="scrollArea"></font></div><div dir="ltr"><font face="monospace"> <property name="widgetResizable"></font></div><div dir="ltr"><font face="monospace"> <bool>true</bool></font></div><div dir="ltr"><font face="monospace"> </property></font></div><div dir="ltr"><font face="monospace"> <widget class="QWidget" name="scrollAreaWidgetContents"></font></div><div dir="ltr"><font face="monospace"> <property name="geometry"></font></div><div dir="ltr"><font face="monospace"> <rect></font></div><div dir="ltr"><font face="monospace"> <x>0</x></font></div><div dir="ltr"><font face="monospace"> <y>0</y></font></div><div dir="ltr"><font face="monospace"> <width>542</width></font></div><div dir="ltr"><font face="monospace"> <height>696</height></font></div><div dir="ltr"><font face="monospace"> </rect></font></div><div dir="ltr"><font face="monospace"> </property></font></div><div dir="ltr"><font face="monospace"> <layout class="QHBoxLayout" name="horizontalLayout"/></font></div><div dir="ltr"><font face="monospace"> </widget></font></div><div dir="ltr"><font face="monospace"> </widget></font></div><div dir="ltr"><font face="monospace"> </item></font></div><div dir="ltr"><font face="monospace"> </layout></font></div><div dir="ltr"><font face="monospace"> </widget></font></div><div dir="ltr"><font face="monospace"> <widget class="QMenuBar" name="menubar"></font></div><div dir="ltr"><font face="monospace"> <property name="geometry"></font></div><div dir="ltr"><font face="monospace"> <rect></font></div><div dir="ltr"><font face="monospace"> <x>0</x></font></div><div dir="ltr"><font face="monospace"> <y>0</y></font></div><div dir="ltr"><font face="monospace"> <width>558</width></font></div><div dir="ltr"><font face="monospace"> <height>24</height></font></div><div dir="ltr"><font face="monospace"> </rect></font></div><div dir="ltr"><font face="monospace"> </property></font></div><div dir="ltr"><font face="monospace"> </widget></font></div><div dir="ltr"><font face="monospace"> <widget class="QStatusBar" name="statusbar"/></font></div><div dir="ltr"><font face="monospace"> </widget></font></div><div dir="ltr"><font face="monospace"> <resources/></font></div><div dir="ltr"><font face="monospace"> <connections/></font></div><div dir="ltr"><font face="monospace"></ui></font></div><div><br></div></div><div dir="ltr"><br></div><div dir="ltr">and the python code, which extends the TableWidget class of my previous message:</div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr"><div dir="ltr"><font face="monospace">from string import ascii_uppercase as letters</font></div><div dir="ltr"><font face="monospace">from PyQt5 import QtCore, QtWidgets, uic</font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace">Days = 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'</font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace">class TableWidget(QtWidgets.QTableWidget):</font></div><div dir="ltr"><font face="monospace"> def sizeHintForColumn(self, column):</font></div><div dir="ltr"><font face="monospace"> model = self.model()</font></div><div dir="ltr"><font face="monospace"> header = self.verticalHeader()</font></div><div dir="ltr"><font face="monospace"> opt = self.viewOptions()</font></div><div dir="ltr"><font face="monospace"> spanned = False</font></div><div dir="ltr"><font face="monospace"> hint = 0</font></div><div dir="ltr"><font face="monospace"> for row in range(model.rowCount()):</font></div><div dir="ltr"><font face="monospace"> if header.isSectionHidden(row):</font></div><div dir="ltr"><font face="monospace"> continue</font></div><div dir="ltr"><font face="monospace"> if self.columnSpan(row, column) > 1:</font></div><div dir="ltr"><font face="monospace"> spanned = True</font></div><div dir="ltr"><font face="monospace"> else:</font></div><div dir="ltr"><font face="monospace"> index = model.index(row, column)</font></div><div dir="ltr"><font face="monospace"> opt.index = index</font></div><div dir="ltr"><font face="monospace"> delegate = self.itemDelegate(index)</font></div><div dir="ltr"><font face="monospace"> hint = max(hint, delegate.sizeHint(opt, index).width())</font></div><div dir="ltr"><font face="monospace"> if spanned and hint:</font></div><div dir="ltr"><font face="monospace"> return hint</font></div><div dir="ltr"><font face="monospace"> return super().sizeHintForColumn(column)</font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace"> def minimumSizeHint(self):</font></div><div dir="ltr"><font face="monospace"> return QtCore.QSize(self.sizeHint().width(), super().minimumSizeHint().height())</font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace"> def sizeHint(self):</font></div><div dir="ltr"><font face="monospace"> width = height = self.frameWidth()</font></div><div dir="ltr"><font face="monospace"> for column in range(self.columnCount()):</font></div><div dir="ltr"><font face="monospace"> width += self.sizeHintForColumn(column) + 1</font></div><div dir="ltr"><font face="monospace"> for row in range(self.rowCount()):</font></div><div dir="ltr"><font face="monospace"> height += self.sizeHintForRow(row) + 1</font></div><div dir="ltr"><font face="monospace"> return QtCore.QSize(</font></div><div dir="ltr"><font face="monospace"> width + self.verticalScrollBar().sizeHint().width(), </font></div><div dir="ltr"><font face="monospace"> height)</font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace">class MainWindow(QtWidgets.QMainWindow):</font></div><div dir="ltr"><font face="monospace"> def __init__(self, tableCount=1):</font></div><div dir="ltr"><font face="monospace"> super().__init__()</font></div><div dir="ltr"><font face="monospace"> uic.loadUi('tables.ui', self)</font></div><div dir="ltr"><font face="monospace"> self.addTables(tableCount)</font></div><div dir="ltr"><font face="monospace"> self.addTableButton.clicked.connect(lambda: self.addTable())</font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace"> def addTables(self, count):</font></div><div dir="ltr"><font face="monospace"> for i in range(count):</font></div><div dir="ltr"><font face="monospace"> self.addTable()</font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace"> def addTable(self, tableName=None):</font></div><div dir="ltr"><font face="monospace"> table = TableWidget()</font></div><div dir="ltr"><font face="monospace"> if tableName is not None:</font></div><div dir="ltr"><font face="monospace"> # get data from database</font></div><div dir="ltr"><font face="monospace"> pass</font></div><div dir="ltr"><font face="monospace"> else:</font></div><div dir="ltr"><font face="monospace"> data = [['Header for table {}'.format(</font></div><div dir="ltr"><font face="monospace"> self.scrollAreaWidgetContents.layout().count() + 1)]]</font></div><div dir="ltr"><font face="monospace"> data += [(i + 1, Days[i % 7], l * 8) for i, l in enumerate(letters)]</font></div><div dir="ltr"><font face="monospace"> rowCount = len(data)</font></div><div dir="ltr"><font face="monospace"> columnCount = 0</font></div><div dir="ltr"><font face="monospace"> for rowData in data:</font></div><div dir="ltr"><font face="monospace"> columnCount = max(columnCount, len(rowData))</font></div><div dir="ltr"><font face="monospace"> table.setRowCount(rowCount)</font></div><div dir="ltr"><font face="monospace"> table.setColumnCount(columnCount)</font></div><div dir="ltr"><font face="monospace"> table.horizontalHeader().setSectionResizeMode(</font></div><div dir="ltr"><font face="monospace"> QtWidgets.QHeaderView.ResizeToContents)</font></div><div dir="ltr"><font face="monospace"> table.horizontalHeader().hide()</font></div><div dir="ltr"><font face="monospace"> table.verticalHeader().hide()</font></div><div dir="ltr"><font face="monospace"> for row, rowData in enumerate(data):</font></div><div dir="ltr"><font face="monospace"> for column, value in enumerate(rowData):</font></div><div dir="ltr"><font face="monospace"> item = QtWidgets.QTableWidgetItem()</font></div><div dir="ltr"><font face="monospace"> item.setData(QtCore.Qt.DisplayRole, value)</font></div><div dir="ltr"><font face="monospace"> table.setItem(row, column, item)</font></div><div dir="ltr"><font face="monospace"> if column == 0:</font></div><div dir="ltr"><font face="monospace"> # assume that there's only one item in this row, and that it is a</font></div><div dir="ltr"><font face="monospace"> # header, so we set its row span</font></div><div dir="ltr"><font face="monospace"> table.setSpan(row, 0, 1, columnCount)</font></div><div dir="ltr"><font face="monospace"> item.setData(QtCore.Qt.TextAlignmentRole, QtCore.Qt.AlignCenter)</font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace"> # it's usually better to add complex widgets to layouts *after* their</font></div><div dir="ltr"><font face="monospace"> # contents have been declared, especially when creation is done at runtime</font></div><div dir="ltr"><font face="monospace"> self.scrollAreaWidgetContents.layout().addWidget(table)</font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace"><br></font></div><div dir="ltr"><font face="monospace">if __name__ == '__main__':</font></div><div dir="ltr"><font face="monospace"> import sys</font></div><div dir="ltr"><font face="monospace"> app = QtWidgets.QApplication(sys.argv)</font></div><div dir="ltr"><font face="monospace"> tableCount, _ = QtWidgets.QInputDialog.getInt(</font></div><div dir="ltr"><font face="monospace"> None, 'Create tables', 'Insert the table count', 3, 1)</font></div><div dir="ltr"><font face="monospace"> mainWindow = MainWindow(tableCount)</font></div><div dir="ltr"><font face="monospace"> mainWindow.show()</font></div><div dir="ltr"><font face="monospace"> sys.exit(app.exec_())</font></div><div><br></div><div>I strongly suggest you to carefully study the above code, look up every function you don't know and do some testing afterwards in order to better understand how it works.</div><div>Open the UI file in Designer and check all the properties of its children, especially the scroll area and its content.</div><div><br></div><div>Good luck!</div><div>Maurizio</div><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></div></div></div></div></div></div></div></div></div>