QTableWidget单元格值未显示在QGIS

时间:2015-11-04 12:10:33

标签: qtablewidget qgis qtablewidgetitem

我想在QGIS插件中使用QTableWidget,以便向用户显示以下列表中的项目:    QTableWidget: tableDomestic

    xnames = ["BOD", "TN", "TP"]
    cat1 = [60, 12, 2.5]
    cat2 = [36, 10.8, 2.4]
    cat3 = [6, 2.4, 2.4]
    cat4 = [3, 2.4, 0.5]

这是我正在使用的代码,当插件运行但是单元格为空时会出现tableDomestic。我想也许我需要一个会使单元格值出现的声明,但到目前为止,通过阅读其他示例我没有找到sthing。我是编程新手,我很感激你的帮助和指导。

     # populate the field table header
    listHeaders = ["1", "2", "3", "4"]
    self.dlg.tableDomestic.setHorizontalHeaderLabels(listHeaders)
    self.dlg.tableDomestic.setVerticalHeaderLabels(xnames)

通常,以下内容应该在一个循环中,但只是为了检查一切是否正常我设置i = 0

    # first column: populate factors for 1st category (cat1)
    BODfactors = QtGui.QTableWidgetItem(cat1[0])
    self.dlg.tableDomestic.setItem(0, 0, BODfactors)

        # second column: populate factors for 2nd category (cat2)
    TNfactors = QtGui.QTableWidgetItem(cat2[0])
    self.dlg.tableDomestic.setItem(0, 1, TNfactors)

        # third column: populate factors for 3rd category (cat3)
    TPfactors = QtGui.QTableWidgetItem(cat3[0])
    self.dlg.tableDomestic.setItem(0, 2, TPfactors)]

1 个答案:

答案 0 :(得分:0)

好的解决了!!

QTableWidget的单元格内的项目应该是字符串!!     cat1 = ['60','12','2.5']     cat2 = ['36','10 .8','2.4']     cat3 = ['6','2.4','2.4']     cat4 = ['3','2.4','0.5']