我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用PySide.QtGui.QTreeView()。
def __init__(self, parent=None): QtGui.QTreeView.__init__(self, parent) self.parent = parent # model = QtGui.QFileSystemModel() model.setFilter(QtCore.QDir.AllEntries | QtCore.QDir.NoDot | QtCore.QDir.NoDotDot | QtCore.QDir.Hidden) model.setNameFilters(["*.stp", "*.step", "*.igs", "*.iges"]) model.setRootPath(QtCore.QDir().homePath()) self.setSortingEnabled(False) self.setModel(model) self.setAlternatingRowColors(True) self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.header().setResizeMode(QtGui.QHeaderView.Stretch) self.hideColumn(1) self.hideColumn(2) self.hideColumn(2) self.hideColumn(3) self.setStyleSheet('''QTreeView {border:1px solid rgb(199, 199, 199);}''')
def display(self, model): app = QtGui.QApplication.instance() if not app: # create QApplication if it doesnt exist app = QtGui.QApplication(sys.argv) tree = QtGui.QTreeView() tree.setModel(model) tree.show() app.exec_() return tree
def setupUi(self, DirectoryViewDialog): DirectoryViewDialog.setObjectName("DirectoryViewDialog") DirectoryViewDialog.resize(408, 337) self.gridLayoutWidget = QtGui.QWidget(DirectoryViewDialog) self.gridLayoutWidget.setGeometry(QtCore.QRect(20, 20, 371, 301)) self.gridLayoutWidget.setObjectName("gridLayoutWidget") self.gridLayout = QtGui.QGridLayout(self.gridLayoutWidget) self.gridLayout.setContentsMargins(0, 0, 0, 0) self.gridLayout.setObjectName("gridLayout") self.gridLayout_2 = QtGui.QGridLayout() self.gridLayout_2.setObjectName("gridLayout_2") self.btnRefresh = QtGui.QPushButton(self.gridLayoutWidget) self.btnRefresh.setObjectName("btnRefresh") self.gridLayout_2.addWidget(self.btnRefresh, 4, 0, 1, 1) self.btnUpload = QtGui.QPushButton(self.gridLayoutWidget) self.btnUpload.setObjectName("btnUpload") self.gridLayout_2.addWidget(self.btnUpload, 0, 0, 1, 1) self.btnDelete = QtGui.QPushButton(self.gridLayoutWidget) self.btnDelete.setObjectName("btnDelete") self.gridLayout_2.addWidget(self.btnDelete, 3, 0, 1, 1) self.btnDownload = QtGui.QPushButton(self.gridLayoutWidget) self.btnDownload.setObjectName("btnDownload") self.gridLayout_2.addWidget(self.btnDownload, 1, 0, 1, 1) self.btnAddFolder = QtGui.QPushButton(self.gridLayoutWidget) self.btnAddFolder.setObjectName("btnAddFolder") self.gridLayout_2.addWidget(self.btnAddFolder, 2, 0, 1, 1) self.gridLayout.addLayout(self.gridLayout_2, 0, 0, 1, 1) self.treeView = QtGui.QTreeView(self.gridLayoutWidget) self.treeView.setObjectName("treeView") self.gridLayout.addWidget(self.treeView, 0, 1, 1, 1) self.buttonBox = QtGui.QDialogButtonBox(self.gridLayoutWidget) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) self.buttonBox.setObjectName("buttonBox") self.gridLayout.addWidget(self.buttonBox, 1, 1, 1, 1) self.retranslateUi(DirectoryViewDialog) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), DirectoryViewDialog.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), DirectoryViewDialog.reject) QtCore.QMetaObject.connectSlotsByName(DirectoryViewDialog)
def __init__(self, title): self.form = [] if title != "Crosspiece": self.partsList = PartsList() else: self.partsList = PartsList(CrossPartWidget) self.tabsList = TabsList() self.params_widget = QtGui.QWidget() self.params_widget.setObjectName("ParamsPanel") self.params_widget.setWindowTitle("Parameters") self.params_vbox = QtGui.QVBoxLayout(self.params_widget) self.form.append(self.params_widget) self.hide_button = None self.show_button = None self.reset_transparency_button = None self.set_transparency_button = None self.active_document = FreeCAD.ActiveDocument self.tree_widget = QtGui.QWidget() self.tree_widget.setObjectName("TreePanel") self.tree_widget.setWindowTitle(title) self.tree_vbox = QtGui.QVBoxLayout(self.tree_widget) self.form.append(self.tree_widget) self.model = TreeModel() self.tree_view_widget = QtGui.QTreeView() self.tree_view_widget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.tree_view_widget.setModel(self.model) self.tree_view_widget.setFixedHeight(250) self.selection_model = None self.tab_type_box = None self.edited_items = [] self.edit_items_layout = None self.init_tree_widget() self.preview_doc = None #self._preview_button = None self.show_other_state_checkbox = None self.other_object_list = [] self.save_initial_objects() self.init_params()