2

を使用してQAbstractItemModelデータを保存し、 を使用しQTreeViewて情報を表示しています。展開矢印を最初の列ではなく 2 番目の列に移動しようとしましたが、うまくいきませんでした。QTableViewa を使用して、各列の動作を定義できるかどうかを確認しようとしましたが、成功しませんでした。何か案は?

以前は をpygtk表示するために使用しTreeViewていましたが、展開矢印を呼び出す列を定義する簡単な方法があります。TreeView.set_expander_arrow()

4

2 に答える 2

3

This can be done easily, but it is not immediately obvious how because QTreeView always displays the expander icons next to model column 0, and there is no way to change that. However, what you can do is change the order in which the model columns are displayed in the view, so model column 0 with its expander icons need not be at the very left.

Put the data you want to show to the left of the expander icons into model column 1 and the data you want to show to the right of the expander icons into model column 0. This is just the other way round as you would normally expect. Then, after populating the tree simply call tree->header()->moveSection(1,0) to move column 1 to the left of column 0.

Credits to Michael Durland who posted this solution on a Qt mailing list.

于 2014-09-17T09:56:02.407 に答える
0

Qt には、展開記号が含まれる列を指定できるネイティブの「ビュー」がありません。

この回答は、任意のアイテムの左側に何かを描画する方法を詳しく説明しているため、必要なシンボルを描画してから、mouseReleaseEvent を上書き、クリックされた領域が描画されたシンボルの 1 つの上にあるかどうかを確認できます (これは役に立ちます)。

申し訳ありませんが、それ以上のことはできませんが、必要な動作を実装するのは非常に大きな作業です! (私は現在 GTK プロジェクトを Qt に自分で移植しているので、いつかこれを実装する必要があるかもしれません。実装する場合は、ここに戻ってコードを投稿します!)

于 2013-12-02T05:24:40.437 に答える