5

QTreeView(QTreeWidgetではない)のアクティブな行を取得して変更する方法はありますか?アクティブとは、選択した行ではなく、フォーカスが強調表示されている行を意味します。ペイントイベントではQStyle.State_HasFocus、アクティブな行を取得するために使用できますが、これは他の場所では機能しないようです。

4

3 に答える 3

4

と の両方にある 関数と を使用して、アクティブな行を取得/設定できますcurrentIndex()(後者は によって返されます)。setCurrentIndex()QTreeViewQItemSelectionModelQTreeView.selectionModel()

その名前にもかかわらず、QItemSelectionModelはビューの現在のアイテムとビューの選択を個別に処理します。

于 2011-09-18T17:20:59.393 に答える
1

Current item is the one which is indicated by the focus rectangle. You can change it using selectionModel function of the tree view. If you don't want to change currently selected items, pass QtGui.QItemSelectionModel.NoUpdate as a second parameter to setCurrentIndex method. Below is an example:

index = model.index(3, 0);
view.selectionModel().setCurrentIndex(index, QtGui.QItemSelectionModel.NoUpdate)

this should move current item to the item with index 3

hope this helps, regards

于 2011-09-18T18:09:18.580 に答える
0

私にとって、そのような質問をすることはここで新しいことではありません。なぜなら単純だからです。Qt-Designer を使用QTreeViewして行編集を作成し、アクション エディターを使用してそれらをリンクし、UI ファイルを Py ファイルに変換すると、舞台裏でどのように動作するかがわかります。
試してみると、これが見つかります:

QtCore.QObject.connect(self.treeView, QtCore.SIGNAL(_fromUtf8("clicked(QModelIndex)")), self.test)
于 2019-02-09T18:49:46.253 に答える