QTreeView(QTreeWidgetではない)のアクティブな行を取得して変更する方法はありますか?アクティブとは、選択した行ではなく、フォーカスが強調表示されている行を意味します。ペイントイベントではQStyle.State_HasFocus
、アクティブな行を取得するために使用できますが、これは他の場所では機能しないようです。
3 に答える
と の両方にある 関数と を使用して、アクティブな行を取得/設定できますcurrentIndex()
(後者は によって返されます)。setCurrentIndex()
QTreeView
QItemSelectionModel
QTreeView.selectionModel()
その名前にもかかわらず、QItemSelectionModel
はビューの現在のアイテムとビューの選択を個別に処理します。
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
私にとって、そのような質問をすることはここで新しいことではありません。なぜなら単純だからです。Qt-Designer を使用QTreeView
して行編集を作成し、アクション エディターを使用してそれらをリンクし、UI ファイルを Py ファイルに変換すると、舞台裏でどのように動作するかがわかります。
試してみると、これが見つかります:
QtCore.QObject.connect(self.treeView, QtCore.SIGNAL(_fromUtf8("clicked(QModelIndex)")), self.test)