#!/usr/bin/env python
import sys
from PyQt4.QtCore import SIGNAL
from PyQt4.QtGui import QApplication
from PyQt4.QtGui import QMainWindow
from PyQt4.QtGui import QTreeWidget
from PyQt4.QtGui import QTreeWidgetItem
class MyTreeItem(QTreeWidgetItem):
def __init__(self, s, parent = None):
super(MyTreeItem, self).__init__(parent, [s])
class MyTree(QTreeWidget):
def __init__(self, parent = None):
super(MyTree, self).__init__(parent)
self.setMinimumWidth(200)
self.setMinimumHeight(200)
for s in ['foo', 'bar']:
MyTreeItem(s, self)
self.connect(self, SIGNAL('itemClicked(QTreeWidgetItem*, int)'), self.onClick)
def onClick(self, item, column):
print item.text(0)
class MainWindow(QMainWindow):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.tree = MyTree(self)
def main():
app = QApplication(sys.argv)
win = MainWindow()
win.show()
app.exec_()
if __name__ == '__main__':
main()
表格QTreeWidget的Item点击事件
最新推荐文章于 2024-07-07 17:22:10 发布