I have the following code to build a result table in Pyqt:
def Tabla(self):
#Boton de exportar a excel
self.toolButton = QtWidgets.QToolButton()
#self.toolButton.setGeometry(QtCore.QRect(30, 190, 41, 31))
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(os.getcwd()+"\images\excel_tras.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.toolButton.setIcon(icon1)
self.toolButton.setObjectName("toolButton")
self.toolButton.clicked.connect(self.exporta)
self.toolButton.setContentsMargins(50, 50, 50, 50)
#Tabla
self.table = QtWidgets.QTableView()
self.table.setObjectName("table")
self.tableWidget = QtWidgets.QTableWidget()
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(len(self.columnas))
self.tableWidget.setRowCount(len(self.listaDatos))
#Colocamos la cabecera
columna = 0
for ele in self.columnas:
item = QtWidgets.QTableWidgetItem(ele)
self.tableWidget.setHorizontalHeaderItem(columna, item)
columna = columna + 1
#Colocamos los datos
fila = 0
for lista in self.listaDatos:
columna = 0
for ele in lista:
self.tableWidget.setItem(fila,columna, QtWidgets.QTableWidgetItem(ele))
columna = columna + 1
fila = fila + 1
#Layout
self.mainLayout.addWidget(self.tableWidget, 6, 0, 5, 7)
self.mainLayout.addWidget(self.toolButton, 5, 5, 1, 1, QtCore.Qt.AlignRight)
And the appearance of the table is as follows: I would like the last column that you see in the image to see the full text ("Media uds sold last three months")
A senior take the question to see if they know some way that you can sort the values of a column ascending or descending as you click on the header.
Thank you!