1
我是一個Python粉絲和一個新手。我發現當我使用InternalPointer獲取文本(項目)在QTreeView可以發生崩潰,所以我在谷歌搜索解決方法,我發現InternalId,但它返回int,但我想用它來獲取文本,呃我不知道如何使用它。 我折騰了很久,但真的不明白,所以我想請你幫我解決這個問題。 希望能夠簡單易懂:) 非常感謝!如何使用InternalId在PyQt4的QTreeView中獲取文本
import sys
from PyQt4 import QtCore, QtGui
from PyQt4.Qt import *
class TreeView(QtGui.QTreeView):
def __init__(self, parent=None):
super(TreeView, self).__init__(parent)
self.connect(self, SIGNAL("clicked(QModelIndex)"), self.getCurrentIndex)
def getCurrentIndex(self, index):
# Use 'InternalId' obtain the corresponding text, not int and hoping to simple.
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
model = QtGui.QDirModel()
tree = TreeView()
tree.setModel(model)
tree.setWindowTitle(tree.tr("Dir View"))
tree.resize(640, 480)
tree.show()
sys.exit(app.exec_())
解決,謝謝! – huyuanqi