0

estoy intentando pasar datos de una lista a un QTableWidget la lista contiene lo siguiente:

[['0.6545454545454545', '67'], ['0.6486486486486487', '14'], ['0.6136363636363636', '38']]

el código que intento es el siguiente:

  fila=0
    for registro in range (NC):
        columna=0
        self.dialogo.TablaResul.insertRow(fila)
        for elemento in range(NC):
            celda=QTableWidgetItem(elemento)
            self.dialogo.TablaResul.setItem(fila,columna,celda)
            columna+=1
        fila+=1

Donde NC es la cantidad de datos a mostrar, pero con ese codigo solo genero las filas y columnas pero los datos no los inserta.

1 respuesta 1

0

Puede que esto te ayude:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, \
    QAction, QTableWidget, QTableWidgetItem, QVBoxLayout


class App(QWidget):

    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 tabla'
        self.left = 0
        self.top = 0
        self.width = 300
        self.height = 200
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)

        self.createTable()
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.tableWidget)
        self.setLayout(self.layout)

        # Mostrar Widget

        self.show()

    def createTable(self):
        data = [['0.6545454545454545', '67'], ['0.6486486486486487',
                '14'], ['0.6136363636363636', '38']]
        f = len(data)  # No. de filas
        c = len(data[0])  # No. de columnas

       # Crea Tabla

        self.tableWidget = QTableWidget()
        self.tableWidget.setRowCount(f)
        self.tableWidget.setColumnCount(c)

        for i in range(f):
            for j in range(c):
                self.tableWidget.setItem(i, j,
                        QTableWidgetItem(data[i][j]))
        self.tableWidget.move(0, 0)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

introducir la descripción de la imagen aquí

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.