2017-08-08 5 views
0

私は、ちょうどので、私はいくつかのことをテストすることができ、私のQtableWidgetからのデータの行を選択し、自分のコンソールにそれらをプリントアウトしようとしているはQTableWidgetからのデータの行全体を選択することはできません

問題文データをプロットすることができます。しかし、私は決してデータの行全体をつかむことはできません。

背景

私は、具体的形式のCSVファイルをインポートすることによって、いくつかのQTableWidgetsを埋め込むことができるGUIを行いました。目標は、同じまたは異なるテーブルから複数の行からデータを取得し、それらを並行してプロットできるようにすることです。データの各行はそれ自身のデータセットであり、それ自身のプロットを持ちますが、同じ図に複数のプロットがあります。

このタスクを完了するには、「Compare」というQpushbuttonが押されたときに開くCompareWindowというウィンドウを作成しました。ウィンドウには、プロットするテーブルの名前とそのテーブルの各行を入力するように求められます。

この情報が送信された後、インスタンス化されたすべてのQTableObjectを保存した参照できる辞書があります。ここで、キーは、対応するテーブルオブジェクトに接続されているテーブルに与えられた名前です。

私は行データをつかむしようとした2つの主な方法がある問題

...

最初のアイデアは私が望んでいた行を反復でしょうTableObject.selectRow()コマンドを使用していたが、私がこれをしたときはいつでも、非型を返すでしょう。

私が試みた2番目の方法は、項目値を追加してリストを1つずつ埋め込むように、特定の行の列を反復することでした。しかし、私がこれをしたときには、Qtableの最初のセルだった同じ番号のリストが繰り返し埋められました。

明示的に特定の行または列を呼び出した場合でも、同じ出力が得られます。プルされる出力は、CSVファイルの最初のセルからの数値である.12です。

ここに問題のコードがあります。問題があります。 https://github.com/Silvuurleaf/Data-Visualize-Project

問題は方法initiateMultiPlotの私のファイルPerspective.pyで発生します。

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 

    """ 

    #calls my class and creates a blank figure where eventually we will plot data on 
    f = CreateFigure.FigureAssembly() 
    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))) 

     #empty list that will store our row data 
     self.Elements = [] 
     try: 
      for rows in rowV: 

       for i in rows: 
        print("rowV value is... {}".format(rowV)) 
        print("current row list{}".format(rows)) 
        print("i value is {}".format(i)) 
        print("itterating") 

        for j in range(self.TableOBJ.columnCount()): 
         print("i value is ...{}".format(i)) 
         print("j value is .... {}".format(j)) 

         #FIRST idea try selecting entire row of data 
         print("i value is ...{}".format(i)) 
         print("j value is .... {}".format(j)) 

         #entire row returns none-type 
         EntireRow = self.TableOBJ.selectRow(i) 
         print(EntireRow) 

         #selecteditems 

         #SECOND idea try using for loop and iterating through every value in a row 
         item = self.TableOBJ.itemAt(i,j) 

         #explicit call for (row 1, col 1) and (row 3, col 3), both which output .12 
         print(self.TableOBJ.itemAt(1,1).text()) 
         print(self.TableOBJ.itemAt(3,3).text()) 
         print("printing item...... {}".format(item)) 
         element = item.text() 
         print(element) 

         #list of .12 
         self.Elements.append(element) 

        #elements = [self.TableOBJ.item(i, j).text() for j in range(self.TableOBJ.columnCount()) if 
        #   self.TableOBJ.item(i, j).text() != ""] 
        #print(elements) 

     except Exception as e: 
      print(e) 

     print(self.Elements) 

は、ここに私のすべてのファイルを含む私のGitHubのリンクです。 CompareWindow.pyファイルは私のPerspective.pyにシグナルを送り、initateMultiPlotに接続します。詳細な説明が必要な場合はお問い合わせください。 documentationによれば

+0

ああ私はあなたに感謝していない!私は –

答えて

1

QTableWidgetItem *QTableWidget::itemAt(int ax, int ay) const

Returns the item at the position equivalent to QPoint(ax, ay) in the table widget's coordinate system, or returns 0 if the specified point is not covered by an item in the table widget.

ある、QTableWidgetに対してグラフィカルな座標で指定されたアイテムのxおよびyを返し、明確あなたが探しているものではありません。

あなたはitem()を使用する必要があります。

QTableWidgetItem *QTableWidget::item(int row, int column) const

Returns the item for the given row and column if one has been set; otherwise returns 0.

しかし、あなたは、以下の変更を行う場合を除き、あなたのケースでは動作しません。

class CreateTable(QTableWidget): 
    .... 
      for j in range(0, m): 
       self.item = QTableWidgetItem(str(round(ValList[j], 6))) 
       # print("{}, {}".format(i, j)) 
       self.setItem(i, j, self.item) 

へ:

class CreateTable(QTableWidget): 
    .... 
      for j in range(0, m): 
       item = QTableWidgetItem(str(round(ValList[j], 6))) 
       # print("{}, {}".format(i, j)) 
       self.setItem(i, j, item) 

すなわち、 self.itemitemに変更します。

最初の一見エラーはかなり難しいですが、QTableWidgetクラスはitem()関数を持っていますが、self.itemステートメントを使用すると、その呼び出しを置き換えます。つまり、Pythonがそのステートメントを読み込んだときに属性と関数ではないので、エラーが発生します:

TypeError 'xxx' object is not callable

+0

うわーありがとう私は決してそれをキャッチしただろう!私は、命名規則が組み込み関数で持つことができる競合を覚えています。私が私のitemAt(i、j)を変更したとき、私のイニシエイトでmultipotが動作しました! –

+0

'ItemAt(x、y)'は、その幾何学的位置に従ってウィジェットを返します。したがって、xの値が小さい場合、常に同じQTableWidgetItem、したがって同じテキストを返します。 – eyllanesc

+0

hmmm私は明確化のために感謝を見る! –

関連する問題