I have a QT Table Widget in Python where I have N columns, for each columns I set a width, but this is not permorming since I could have some text that is bigger than the width I gave them, how can I say for each column a minimun Widht (for example if the cell is empty I don't want the column to disappear, I want to show the title) and also to resize the columns width to text? this is my code:
class elencoviaggi(QtWidgets.QDialog):
def __init__(self):
super(elencoviaggi, self).__init__()
uic.loadUi('elenco_reg.ui', self)
self.tabella_registrazioni.setColumnWidth(0, 30)
self.tabella_registrazioni.setColumnWidth(1, 100)
self.tabella_registrazioni.setColumnWidth(2, 80)
self.tabella_registrazioni.setColumnWidth(3, 105)
for row in c.execute("SELECT * FROM Viaggi "):
righe = self.tabella_registrazioni.rowCount()
self.tabella_registrazioni.setRowCount(righe+1)
self.tabella_registrazioni.setItem(tablerow, 0, QtWidgets.QTableWidgetItem(str(row[0])))
self.tabella_registrazioni.setItem(tablerow, 1, QtWidgets.QTableWidgetItem(row[1]))
self.tabella_registrazioni.setItem(tablerow, 2, QtWidgets.QTableWidgetItem(row[2]))