def _layout(self): layout = QHBoxLayout(self) self.setLayout(layout) self.tree = QTreeView(self) self.tree.setModel(self.model) self.tree.setUniformRowHeights(True) self.tree.setColumnWidth(0, 200) self.tree.setDragEnabled(True) self.tree.setDragDropMode(QAbstractItemView.InternalMove) self.tree.viewport().setAcceptDrops(True) layout.addWidget(self.tree, 1) buttons = QVBoxLayout() buttons.setAlignment(Qt.AlignTop) add_button = QPushButton(QIcon.fromTheme("list-add"), "", self) add_button.setToolTip("Add application") add_button.clicked.connect(self.on_add) buttons.addWidget(add_button) mkdir_button = QPushButton(QIcon.fromTheme("folder-new"), "", self) mkdir_button.setToolTip("Make directory") mkdir_button.clicked.connect(self.on_mkdir) buttons.addWidget(mkdir_button) delete_button = QPushButton(QIcon.fromTheme("list-remove"), "", self) delete_button.setToolTip("Remove selected item") delete_button.clicked.connect(self.on_delete) buttons.addWidget(delete_button) layout.addLayout(buttons)
def __init__(self, vfs_view, *args, **kwargs): QWidget.__init__(self, *args, **kwargs) self.vnode_2click_selected = None # Getting the Model self.source_model = VfsDirModel() # Creating a QTableView self.view = QTreeView() self.view.doubleClicked.connect(self.double_clicked) self.view.clicked.connect(self.clicked) self.view.setSelectionBehavior(QAbstractItemView.SelectRows) self.view.setSelectionMode(QAbstractItemView.ExtendedSelection) font = self.view.font() font.setPointSize(8) self.view.setFont(font) self.view.setModel(self.source_model) # # QTableView Headers self.header = self.view.header() self.header.setSectionResizeMode(QHeaderView.ResizeToContents) self.header.setStretchLastSection(True) size = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) size.setHorizontalStretch(1) self.view.setSizePolicy(size) self.main_layout = QHBoxLayout() self.main_layout.addWidget(self.view) self.setLayout(self.main_layout) self.source_model.vfs_view_set(vfs_view)
def __init__(self, parent=None): super().__init__(parent) self._recursiveActivated = False self._model = FolderListModel(self) self._completer = QCompleter(self._model, self) self._completer.setCompletionColumn(3) self._lineedit = TabCompletionLineEdit(self._completer, self) self._view = QTreeView(self) self._view.setModel(self._model) self._model.folderChanged.connect(self._lineedit.setText) self._model.setFolder(".") self._view.header().setSectionResizeMode(0, QHeaderView.Interactive) self._view.header().setSectionResizeMode(1, QHeaderView.ResizeToContents) self._view.header().setSectionResizeMode(2, QHeaderView.ResizeToContents) self._view.header().resizeSection(0, 500) self._view.header().setSectionHidden(3, True) layout = QVBoxLayout(self) layout.addWidget(self._lineedit) layout.addWidget(self._view) self.setLayout(layout) self._view.activated.connect(self._activated) self.activated.connect(self._lineedit.setText) self._lineedit.returnPressed.connect(self._leActivated, Qt.QueuedConnection) self._lineedit.textEdited.connect(self._leTextEdited)
def __init__(self, *args): super().__init__() self.setFixedSize(930, 631) self.setLocale(QLocale(QLocale.English, QLocale.UnitedStates)) self.setWindowTitle( QCoreApplication.translate("MainWindow", "PyInspect")) self.central_widget = QWidget(self) self.comboBox = QComboBox(self.central_widget) self.comboBox.setGeometry(QRect(10, 10, 451, 22)) self.comboBox.setMouseTracking(False) self.comboBox.setMaxVisibleItems(5) self.comboBox.setObjectName("comboBox") for _backend in backend.registry.backends.keys(): self.comboBox.addItem(_backend) self.tree_view = QTreeView(self.central_widget) self.tree_view.setGeometry(QRect(10, 40, 451, 581)) self.tree_view.setColumnWidth(0, 150) self.comboBox.setCurrentText('uia') self.__show_tree() self.table_view = QTableView(self.central_widget) self.table_view.setGeometry(QRect(470, 40, 451, 581)) self.comboBox.activated[str].connect(self.__show_tree) self.tree_view.clicked.connect(self.__show_property)
def init_ui(self): '''Initializes the UI''' self.setWindowTitle(self.title) self.model = QFileSystemModel() self.model.setRootPath(ROOT_PATH) self.tree = QTreeView() self.tree.setModel(self.model) self.tree.setRootIndex(self.model.index(self.root_path)) self.start_box = QLineEdit() self.stop_box = QLineEdit() self.start_box.setValidator(QIntValidator()) self.stop_box.setValidator(QIntValidator()) self.make_btn = QPushButton("Create Project Folders") self.make_btn.clicked.connect(self.on_btn) layout = QVBoxLayout() layout.addWidget(self.tree) subgrid = QGridLayout() subgrid.addWidget(self.start_box, 0, 1) subgrid.addWidget(self.stop_box, 1, 1) subgrid.addWidget(QLabel('From (inc.): '), 0, 0) subgrid.addWidget(QLabel('To (not inc.): '), 1, 0) layout.addLayout(subgrid) layout.addWidget(self.make_btn) self.setLayout(layout) self.show()
def __init__(self): super().__init__() self.chapter_data = None self.dispos_model = None self.dispos = None self.terrain = None self.tiles_model = None self.terrain_mode = False self.initialized_selection_signal = False self.selected_faction = None left_panel_container = QWidget() left_panel_layout = QVBoxLayout() self.toggle_editor_type_checkbox = QCheckBox() self.toggle_editor_type_checkbox.setText("Spawns/Terrain") self.toggle_editor_type_checkbox.setChecked(True) self.toggle_editor_type_checkbox.stateChanged.connect( self._on_mode_change_requested) self.toggle_coordinate_type_checkbox = QCheckBox() self.toggle_coordinate_type_checkbox.setText( "Coordinate (1)/Coordinate (2)") self.toggle_coordinate_type_checkbox.setChecked(True) self.toggle_coordinate_type_checkbox.stateChanged.connect( self._on_coordinate_change_requested) self.tree_view = QTreeView() left_panel_layout.addWidget(self.toggle_editor_type_checkbox) left_panel_layout.addWidget(self.toggle_coordinate_type_checkbox) left_panel_layout.addWidget(self.tree_view) left_panel_container.setLayout(left_panel_layout) self.grid = FE14MapGrid() self.dispos_scroll, self.dispos_form = PropertyForm.create_with_scroll( dispo.SPAWN_TEMPLATE) self.terrain_form, self.terrain_persistent_editors, self.tile_form = _create_terrain_form( ) self.organizer = QSplitter() self.organizer.addWidget(left_panel_container) self.organizer.addWidget(self.grid) self.organizer.addWidget(self.dispos_scroll) main_layout = QVBoxLayout(self) main_layout.addWidget(self.organizer) self.setLayout(main_layout) self.add_faction_shortcut = QShortcut(QKeySequence("Ctrl+F"), self) self.add_item_shortcut = QShortcut(QKeySequence("Ctrl+N"), self) self.grid.focused_spawn_changed.connect(self._on_focused_spawn_changed) self.add_faction_shortcut.activated.connect( self._on_add_faction_requested) self.add_item_shortcut.activated.connect(self._on_add_item_requested) self.dispos_form.editors["PID"].editingFinished.connect( self._on_pid_field_changed) self.dispos_form.editors["Team"].currentIndexChanged.connect( self._on_team_field_changed) self.dispos_form.editors["Coordinate (1)"].textChanged.connect( self._on_coordinate_1_field_changed) self.dispos_form.editors["Coordinate (2)"].textChanged.connect( self._on_coordinate_2_field_changed)
def __init__(self): if not path.exists(algorithm_directory): os.makedirs(algorithm_directory, exist_ok=True) self.fmodel = QFileSystemModel() self.fmodel.setRootPath(algorithm_directory) self.module_list = QTreeView() self.module_list.setModel(self.fmodel) self.module_list.setRootIndex(self.fmodel.index(algorithm_directory)) self.module_button = QPushButton("Change Directory") self.module_button.clicked.connect(self.change_dir) self.start_date = ToggleButton('Start Date') self.end_date = ToggleButton('End Date', 'Default (Present)') self.test_types = ['Profit', 'Accuracy'] self.test_type = QComboBox() self.test_type.addItems(self.test_types) self.test_output = QTextEdit() self.test_output.setDisabled(True) self.run_btn = QPushButton('Run Test') self.profit = QLCDNumber() self.accuracy = QLCDNumber() super().__init__('Jencks Stock Algorithm Tester')
def createLeftSide(self): self.leftSideGB = QGroupBox() home_directory = "./app/" palette = QPalette() palette.setColor(QPalette.Window, QColor(30, 30, 30)) model = QDirModel() view = QTreeView() view.setStyleSheet("QTreeView { border: 0px; }") view.setModel(model) view.setRootIndex(model.index(home_directory)) view.setColumnHidden(1, True) view.setColumnHidden(2, True) view.setColumnHidden(3, True) view.show() view.setPalette(palette) runButton = QPushButton("►") stopButton = QPushButton("❚❚") bottomBar = QHBoxLayout() bottomBar.addWidget(runButton) bottomBar.addWidget(stopButton) layout = QVBoxLayout() layout.addWidget(view) layout.addLayout(bottomBar) layout.setStretch(0, 2) self.leftSideGB.setLayout(layout)
def __init__(self, parent=None): super().__init__(parent) self.model = ExportChangesModel() self.error_dialog = None self.setWindowIcon(QIcon("paragon.ico")) self.setWindowTitle("Export") main_layout = QVBoxLayout(self) self.export_button = QPushButton() self.export_button.setText("Export") self.main_view = QTreeView() self.main_view.setModel(self.model) self.main_view.setHeaderHidden(True) self.main_view.setEditTriggers( QtWidgets.QAbstractItemView.NoEditTriggers) self.remember_selections_checkbox = QCheckBox() self.remember_selections_checkbox.setText("Remember selections.") main_layout.addWidget(self.export_button) main_layout.addWidget(self.main_view) main_layout.addWidget(self.remember_selections_checkbox) self.setLayout(main_layout) self.main_view.expanded.connect(self._on_item_expanded) self.export_button.clicked.connect(self._on_export_triggered) self.remember_selections_checkbox.stateChanged.connect( self._on_remember_selections_state_changed) self._set_remember_checkbox_state_from_settings()
def component_tree_view(template, model, component_model, qtbot): component_tree_view = QTreeView(template) component_delegate = ComponentEditorDelegate(component_tree_view, model) component_tree_view.setItemDelegate(component_delegate) component_tree_view.setModel(component_model) qtbot.addWidget(component_tree_view) template.ui = component_tree_view return component_tree_view
def __init__(self, title, central_widget, parent=None): super().__init__(title, parent=parent) self.central_widget = central_widget self.model = QFileSystemModel() self.model.setRootPath(QDir.currentPath()) self.tree = QTreeView() self.tree.pressed.connect(self.setIndex) self.index_ = None self.db_tree = QTreeView() self.db_tree.setAnimated(True) self.db_model = QStandardItemModel() self.db_model.setHorizontalHeaderLabels(["Database"]) self.db_root = self.db_model.invisibleRootItem() self.dbs = []
def read(self, index): putanja = self.dock.model.filePath(index) if os.path.isdir(putanja): return ista_putanja = False for i in range(len(self.lista_putanja)): if putanja == self.lista_putanja[i]: ista_putanja = True return if not ista_putanja: self.lista_putanja.append(putanja) if putanja.find(".sql") != -1: self.connection = mysql.connector.connect(user="******", password="******", host="127.0.0.1", database="projekat") self.csor = self.connection.cursor() putanja = "podaci\metaPodaci\projekat_meta_podaci.csv" meta_podaci = citanje_meta_podataka(putanja, True) self.imena_tabela = meta_podaci[4].split(",") self.treeView = QTreeView() self.treeView.setContextMenuPolicy(Qt.CustomContextMenu) self.treeView.customContextMenuRequested.connect(self.dugme_baza) model = QStandardItemModel(parent=self.dock.tree.sub_layout) item = QStandardItem("zatvori") item.setEditable(False) model.appendRow(item) for text in self.imena_tabela: item = QStandardItem(text) item.setEditable(False) model.appendRow(item) self.treeView.setModel(model) self.treeView.clicked.connect(self.dugme_baza) self.treeView.PositionAtBottom si = self.dock.tree.sub_layout.sizeHint() si.setWidth(self.dock.width()) si.setHeight(200) self.treeView.setFixedSize(si.width(), si.height()) self.treeView.setHeaderHidden(True) self.dock.tree.sub_layout.addWidget(self.treeView) self.dock.tree.sub_layout.setAlignment(self.treeView, QtCore.Qt.AlignBottom) return tab = Tab(putanja, parent=self.central_widget) tab.pocetna_strana = self if putanja != "": tab.read() else: tab.read(putanja) tab.btn_down.clicked.connect(self.otvori_tabelu_dete) tab.btn_up.clicked.connect(self.otvori_tabelu_roditelj) tab.naziv = tab.meta_podaci[0] self.central_widget.addTab(tab, tab.naziv) self.central_widget.setCurrentIndex(self.central_widget.currentIndex()+1)
def __init__(self, index_filename): QWidget.__init__(self) self.data_index = pd.DataFrame() self.data_info = aecg.tools.indexer.StudyInfo() self.data_index_stats = aecg.tools.indexer.StudyStats( self.data_info, self.data_index) # Getting the Models self.project_loaded = '' self.projectmodel = ProjectTreeModel() # Creating a QTreeView for displaying the selected project index self.project_treeview = QTreeView() self.project_treeview.setModel(self.projectmodel) self.phorizontal_header = self.project_treeview.header() self.phorizontal_header.setSectionResizeMode( QHeaderView.ResizeToContents) self.phorizontal_header.setStretchLastSection(True) self.sp_right = QSplitter(Qt.Orientation.Horizontal) self.sp_left = QSplitter(Qt.Orientation.Vertical, self.sp_right) # NavigationWidget Layout self.main_layout = QVBoxLayout() size = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) # Left side # Left side - Top layout # Left side - Bottom Layout size.setVerticalStretch(4) self.project_treeview.setSizePolicy(size) self.sp_left.addWidget(self.project_treeview) # Right side size = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) size.setHorizontalStretch(2) size.setHeightForWidth(False) self.tabdisplays = TabDisplays(self) self.sp_right.addWidget(self.tabdisplays) self.tabdisplays.validator_data_ready.connect( self.load_projectindex_after_validation) self.sp_right.setSizePolicy(size) # Set the layout to the QWidget self.main_layout.addWidget(self.sp_right) self.setLayout(self.main_layout) self.tabdisplays.setCurrentWidget(self.tabdisplays.validator) # Load study index if index_filename and (index_filename != ""): if os.path.exists(index_filename): self.load_projectindex(os.path.normpath(index_filename)) else: QMessageBox.warning(self, f"Study index file not found", f"{index_filename} not found")
def __init__(self): super(MainWindow, self).__init__() self.model = Project() self.view = QTreeView(self) self.view.setModel(self.model) self.view.setDragEnabled(True) self.view.setDragDropMode(QAbstractItemView.InternalMove) self.setCentralWidget(self.view)
def __init__(self, parent=None): QWidget.__init__(self, parent) self.treeView = QTreeView(self) layout = QVBoxLayout() layout.addWidget(self.treeView) self.setLayout(layout) self.treeView.setModel(QStandardItemModel()) self.treeView.model().setHorizontalHeaderLabels(('3', '1', '5'))
def __init__(self): QDockWidget.__init__(self, "File Menager") self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea) model = QFileSystemModel() model.setRootPath(QDir.currentPath()) tree = QTreeView() tree.setModel(model) self.setWidget(tree)
def __init__(self): QWidget.__init__(self) layout = QVBoxLayout(self) self.splitter = QSplitter(self) self.tree = QTreeView(self) self.tree.setSortingEnabled(True) self.tree.setModel(ForumModel()) self.splitter.addWidget(self.tree) layout.addWidget(self.splitter) self.setLayout(layout)
def fileList(self): #树状文件列表 self.model = QDirModel() self.view = QTreeView(self) self.view.setModel(self.model) self.view.setColumnHidden(1, True) self.view.setColumnHidden(2, True) self.view.setColumnHidden(3, True) self.view.setHeaderHidden(True) #self.view.setRootIndex(self.model.index("c:/")) self.layout.addWidget(self.view, 0, 0, 2, 1)
def __initFileTreeView__(self, model): treeView = QTreeView() treeView.setIndentation(20) treeView.setSortingEnabled(True) treeView.setMinimumWidth(100) treeView.setModel(model) treeView.setRootIndex(model.index(r'C:')) for i in range(1, 5): treeView.hideColumn(i) return treeView
def display(self, model): app = QApplication.instance() # Create QApplication if it does not exist if not app: app = QApplication(sys.argv) tree = QTreeView() tree.setModel(model) tree.show() app.exec_() return tree
def __init__(self): super().__init__() self.setWindowTitle('World Country Diagram') self.resize(500, 700) treeView = QTreeView() treeView.setHeaderHidden(True) treeModel = QStandardItemModel() rootNode = treeModel.invisibleRootItem() # America america = StandardItem('America', 16, set_bold=True) california = StandardItem('California', 14) america.appendRow(california) oakland = StandardItem('Oakland', 12, color=QColor(155, 0, 0)) sanfrancisco = StandardItem('San Francisco', 12, color=QColor(155, 0, 0)) sanjose = StandardItem('San Jose', 12, color=QColor(155, 0, 0)) california.appendRow(oakland) california.appendRow(sanfrancisco) california.appendRow(sanjose) texas = StandardItem('Texas', 14) america.appendRow(texas) austin = StandardItem('Austin', 12, color=QColor(155, 0, 0)) houston = StandardItem('Houston', 12, color=QColor(155, 0, 0)) dallas = StandardItem('dallas', 12, color=QColor(155, 0, 0)) texas.appendRow(austin) texas.appendRow(houston) texas.appendRow(dallas) # Canada canada = StandardItem('Canada', 16, set_bold=True) alberta = StandardItem('Alberta', 14) bc = StandardItem('British Columbia', 14) ontario = StandardItem('Ontario', 14) canada.appendRows([alberta, bc, ontario]) rootNode.appendRow(america) rootNode.appendRow(canada) treeView.setModel(treeModel) treeView.expandAll() treeView.doubleClicked.connect(self.getValue) self.setCentralWidget(treeView)
def __init__(self, parent, f=...): super().__init__(parent, f) self.project = Project() self.current_tree_item: Optional[Container] = None self.main_splitter = self # inheritance from QSplitter may not be preserved self.main_splitter.setOrientation(Qt.Horizontal) self.left_splitter = QSplitter(Qt.Vertical) self.right_splitter = QSplitter(Qt.Vertical) self.main_splitter.addWidget(self.left_splitter) self.main_splitter.addWidget(self.right_splitter) # self.w_parameters = ParametersWidget(self.project.bundle) self.w_parameters_tree = QTreeView() self.w_parameters_tree.setModel(self.project.parameters_model) delegate = ParametersTableDelegate() self.w_parameters_tree.setItemDelegate(delegate) self.selection_model_parameters = self.w_parameters_tree.selectionModel( ) self.selection_model_parameters.currentRowChanged.connect( self._on_tree_row_changed) self.w_curves_tree = QTreeView() self.w_curves_tree.setModel(self.project.curves_model) delegate = CurvesTableDelegate() self.w_curves_tree.setItemDelegate(delegate) self.selection_model_curves = self.w_curves_tree.selectionModel() self.selection_model_curves.currentRowChanged.connect( self._on_tree_row_changed) self.w_light_plot = LightPlotWidget(self.project.curves_model) self.w_rv_plot = RvPlotWidget(self.project.curves_model) self.left_splitter.addWidget(self.w_parameters_tree) self.left_splitter.addWidget(self.w_curves_tree) self.right_splitter.addWidget(self.w_light_plot) self.right_splitter.addWidget(self.w_rv_plot)
def __init__(self, *args): super(RightPanel, self).__init__(*args) self.connect_signals() self.label.setText('Recipe') self.tree_view = QTreeView() self.model = RecipeModel() self.tree_view.setModel(self.model) self.tree_view.setWordWrap(True) self.tree_view.setColumnWidth(0, 50) self.widget_layout.addWidget(self.tree_view) signals.update_recipe.emit()
def setupUi(self): """Init. the UI.""" self.setWindowIcon(QIcon(ICON)) # === Widgets === # TreeView model = QtGui.QStandardItemModel(0, 1) model.setHorizontalHeaderLabels(["Class"]) self.treeView = QTreeView() self.treeView.rootNode = model.invisibleRootItem() self.treeView.setModel(model) self.treeView.setAlternatingRowColors(False) # size options # setting min. width in self.generate to fit content self.treeView.setContextMenuPolicy(Qt.CustomContextMenu) # Hide Debug Columns # self.treeView.hideColumn(1) # text output self.text = QLabel() self.text.setAlignment(Qt.AlignTop) self.text.setWordWrap(True) self.text.setMinimumWidth(300) # Splitters self.splitter = QSplitter(self) self.splitter.setStretchFactor(0, 0) self.splitter.setStretchFactor(1, 1) self.splitter.addWidget(self.treeView) self.splitter.addWidget(self.text) # dialog buttons self.buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel ) # window to create confirmation and cancellation buttons # === Layout === # Horizontal Div. layout = QVBoxLayout() # layout.setContentsMargins(0, 0, 0, 0) # layout.setSpacing(0) layout.addWidget(self.splitter) layout.addWidget(self.buttons) self.setLayout(layout)
def __init__(self, root_path) -> None: QWidget.__init__(self) # self.index stores the index of the latest item which is clicked # self.root_path is the path to the folder currently showing self.index = None self.root_path = os.path.abspath(root_path) self.dir_view = QTreeView() self.model = QFileSystemModel(self.dir_view) self.model.setRootPath(self.root_path) self.dir_view.clicked.connect(self.onFileItemClicked) self.dir_view.doubleClicked.connect(self.onFileItemDoubleClicked) self.dir_view.setModel(self.model) self.dir_view.setRootIndex(self.model.index(self.root_path)) open_button = QPushButton("Open") open_button.clicked.connect(self.openFile) open_in_file_explorer_button = QPushButton("Open in File Explorer") open_in_file_explorer_button.clicked.connect(self.openInFileExplorer) self.root_path_line_edit = QLineEdit(self.root_path) self.root_path_line_edit.returnPressed.connect( self.onChangeLineEditReturned) self.root_path_line_edit.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self.root_path_line_edit.adjustSize() change_path_button = QPushButton('Change Directory') change_path_button.clicked.connect(self.onChangeButtonClicked) addressCompleter = QCompleter() addressCompleter.setModel(self.model) self.root_path_line_edit.setCompleter(addressCompleter) # Set layout layout = QGridLayout() layout.addWidget(self.root_path_line_edit, 0, 0, 1, 1) layout.addWidget(change_path_button, 0, 1, 1, 1) layout.addWidget(self.dir_view, 1, 0, 1, 2) layout.addWidget(open_button, 2, 0, 1, 1) layout.addWidget(open_in_file_explorer_button, 2, 1, 1, 1) layout.setMargin(0) self.setLayout(layout)
def __init__(self, dir_path): super().__init__() # appWidth = 800 # appHeight = 300 self.setWindowTitle('File System Viewer') # self.setGeometry(300, 300, appWidth, appHeight) self.model = QFileSystemModel() self.model.setRootPath(dir_path) self.tree = QTreeView() self.tree.setModel(self.model) self.tree.setRootIndex(self.model.index(dir_path)) self.tree.setColumnWidth(0, 250) self.tree.setAlternatingRowColors(True) layout = QVBoxLayout() layout.addWidget(self.tree) self.setLayout(layout)
def setupUi(self): """Setup the UI""" # === Widgets === # TreeView self.treeView = QTreeView() # self.treeView.rootNode = model.invisibleRootItem() self.treeView.setModel(self.model) self.treeView.setAlternatingRowColors(False) # self.treeView.setColumnWidth(0, 150) self.treeView.setMinimumWidth(100) self.treeView.setContextMenuPolicy(Qt.CustomContextMenu) self.selectionModel = self.treeView.selectionModel() self.statusBar = QStatusBar() self.statusBar.setSizeGripEnabled(False) self.statusBar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) self.statusBar.setStyleSheet( "QStatusBar {border: 1px solid rgb(200, 200, 200)}") self.saveLabel = QLabel("unsaved") self.saveLabel.setVisible(False) self.statusBar.addPermanentWidget(self.saveLabel) # Splitters self.leftSplitter = QSplitter() self.leftSplitter.setStretchFactor(0, 0) self.leftSplitter.setStretchFactor(1, 1) # === Layout === # Horizontal Div. self.hLayout = QVBoxLayout() self.hLayout.setContentsMargins(0, 0, 0, 0) self.hLayout.setSpacing(0) # add widgets to layout self.hLayout.addWidget(self.leftSplitter) self.hLayout.addWidget(self.statusBar) # add widgets self.leftSplitter.addWidget(self.treeView) self.setLayout(self.hLayout)
def create_ui_contents(parent: Union[QWidget, QMainWindow], layout: QVBoxLayout) -> QLabel: """ Fill either Window or Widget example with UI Elements """ label = QLabel('Drag file from your local file system on this window', parent) layout.addWidget(label) file_label = QLabel('<No file set>') layout.addWidget(file_label) tree_view = QTreeView(parent) tree_view.drag_n_drop_handler = DragNDropHandler(tree_view) tree_view.drag_n_drop_handler.file_dropped.connect(file_label.setText) layout.addWidget(tree_view) print(type(parent), parent.__class__) parent.setWindowTitle('DnD Example Window' if type(parent) is ExampleWindow else 'DnD Example Widget') parent.setGeometry(800, 600, 800, 400) parent.setAcceptDrops(True) return file_label
def __init__(self, parent=None): super(Form, self).__init__(parent) # Create widgets self.edit = QLineEdit("Write my name here") self.button = QPushButton("Show Greetings") self.tree = QTreeView() model = QFileSystemModel() model.setRootPath(QDir.currentPath()) # Create layout and add widgets layout = QVBoxLayout() layout.addWidget(self.edit) layout.addWidget(self.button) layout.addWidget(self.tree) # Set dialog layout self.setLayout(layout) # Add button signal to greetings slot self.button.clicked.connect(self.greetings)
def __init__(self, context): super(TriageFilePicker, self).__init__() self.context = context self.actionHandler = UIActionHandler() self.actionHandler.setupActionHandler(self) self.contextMenu = Menu() self.contextMenuManager = ContextMenuManager(self) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.model = QFileSystemModel() self.model.setRootPath("") self.model.setFilter(QDir.AllEntries | QDir.Hidden | QDir.System) self.tree = QTreeView(self) self.tree.setModel(self.model) self.tree.setSelectionMode(QAbstractItemView.ExtendedSelection) self.tree.setColumnWidth(0, 500) layout.addWidget(self.tree, 1) self.setLayout(layout) self.tree.doubleClicked.connect(self.onDoubleClick) recentFile = QSettings().value("triage/recentFile", os.path.expanduser("~")) while len(recentFile) > 0: f = self.model.index(recentFile) if f.isValid(): self.tree.scrollTo(f) self.tree.setExpanded(f, True) break parentDir = os.path.dirname(recentFile) if parentDir == recentFile: break recentFile = parentDir self.actionHandler.bindAction( "Open Selected Files", UIAction(lambda context: self.openSelectedFiles(), lambda context: self.areFilesSelected())) self.contextMenu.addAction("Open Selected Files", "Open")