0

基本的に、最初の関数では、マウスを使用して選択したセルを取得し、data()メソッドを使用してそのセルからデータを取得し、最初の関数で表示することができます。

ただし、セルを選択すると、その行の最初のセル(最初の列)のデータが表示されるように少し変更したいと思います。選択したセルのindex(currentCell)がすでにあるので、新しいModelIndexオブジェクトをインスタンス化して、選択したインデックスをそれに割り当てます。次に、オブジェクトの列を0に変更します。最後に、data()mtohodを使用して新しいオブジェクトでデータを取得したいのですが、何もありませんでした。nullです。多くの時間を費やしていて、何であるかわかりません。問題。助けて読むためにいくつかの努力を提供してくれた人に感謝します:)

def tbRobotChanged(self, currentCell):          
 # get the selected cell's index from currentCell,Implement the Slot method

    self.statusBar().showMessage("Slected Robot is "+ 
    currentCell.data().toString())

def tbRobotChangedt(self,currentCell):

    crow_header_Index =  QtCore.QModelIndex()
    crow_header_Index = currentCell
    crow_header_Index.column = 0

    self.statusBar().showMessage("Slected Robot:"+crow_header_Index.data().toString())
4

1 に答える 1

0

QModelIndexそのようなインスタンスを構築または変更することはできません。それらを作成して渡すのがモデルの仕事です。その行の最初の列について、モデル (.indexメソッド) に問い合わせる必要があります。QModelIndex

def tbRobotChangedt(self,currentCell):

    model = currentCell.model()
    # or if you keep your model in a variable, use it.

    # .index normally takes 3 arguments.
    # row, column, parent
    # If this is a table model, you won't need the third argument.
    # because table is flat. no parents
    firstColumn = model.index(currentCell.row(), 0)

    # then get data as usual
    self.statusBar().showMessage("Selected Robot: %s" % firstColumn.data().toString())
于 2013-02-07T07:07:55.477 に答える