当我尝试打印QtableWidget的索引时,会出现奇怪的输出?

2024-04-16 11:36:37 发布

您现在位置:Python中文网/ 问答频道 /正文

背景信息

我创建了一个名为自我表格对象我很难从中找到信息。你知道吗

现在我正在尝试选择给定整数的对应行,但是当我这样做并尝试打印我的行时,它将返回none。你知道吗

这让我相信我引用对象的方式是不正确的。你知道吗

所以我试着访问QtableWidget的垂直索引,看看是否可以得到任何输出,但是当我这样做时,它会返回以下结果。。。你知道吗

<PyQt5.QtCore.QModelIndex object at 0x00000000047BC5F8>

问题

有人能解释为什么输出是这种格式,以及如何将其转换为实际的索引列表吗?你知道吗

如果有人能帮我选择QtableWidget的行,那也会很有帮助。你知道吗

def initiateMultiPlot(self, tableV, rowV, PlotV):
    """
        1. Match TableName values with the key values in our TableDB
        2. When we find a  match look at that key's corresponding Table Object, and iterate
        through that objects rows and select the rows specified by rowV
        3.Call plot for those values

    """
    f = createFIG()
    print("")
    for i in tableV:
        """
            tableV: is list of strings that represent assigned tablenames [Table1, Table2, Table3]
            rowV: is a list, containing lists representing rows from corresponding Tables the user wishes to plot.
                for example [[1,2],[3,4],[1]] means rows 1,2 from table1, rows 3,4 from table2... so on
            PlotV: is a string that is ethier "box" or "whisker" to tell what method to plot. Default right now 
            is to do a simple boxplot
        """
        print("Creating table instance")

        #Table Dictionary is setup so the names of the Tables (tableV) are the keys of the dictionary
        # and the actual table objects are referenced by these keys
        self.TableOBJ = self.TableDictionary[i]
        print("Data Type for the table object is..................{}".format(type(self.TableOBJ)))

        #for i in range(self.TableOBJ.rowCount()):
        # try:
        #     self.TableOBJ.setVerticalHeaderLabels(arange(self.TableOBJ.rowCount()))
        # except Exception as e:
        #     print(e)


        ### Test to see if I can print any output from my object###

        print((self.TableOBJ.currentIndex()))
        for j in rowV:
              for k in j:
                print("selecting rows")
                print(self.TableOBJ.selectRow(k))

                x = self.TableOBJ.selectRow(k)
                print("x data is here before plot command is issued................... {}".format(x))
                #ColHeader is the horizontal header for my QtableWidget, and is just a list of strings.
                y = self.TableOBJ.ColHeader
                f.plotData(x,y,PlotV, False)


    f.plt.show()

完整代码:https://github.com/Silvuurleaf/Data-Analysis-and-Visualization-GUI/blob/master/Plotter4.1

这个问题源于我的类主窗口中的第299行

用于上载数据的文件:https://github.com/Silvuurleaf/Data-Analysis-and-Visualization-GUI/blob/master/Test%206.csv


Tags: andofthetoinselfforthat