def setUpMainWindow(self): """Set up the GUI's main window.""" search_line_edit = QLineEdit() search_line_edit.setPlaceholderText( "Enter text to search for a word below") list_of_words = self.loadWordsFromFile() list_view = QListView() # Create a model instance and pass the list of words to the model model = ListModel(list_view, list_of_words) list_view.setModel(model) # Create QCompleter object that shares the same model as the QListView completer = QCompleter(list_of_words) completer.setFilterMode(Qt.MatchFlag.MatchStartsWith) completer.setModel(model) search_line_edit.setCompleter( completer) # Set the completer for the QLineEdit # Create a layout and organize all of the objects # into a QGroupBox main_v_box = QVBoxLayout() main_v_box.addWidget(search_line_edit) main_v_box.addWidget(list_view) word_group_box = QGroupBox("Keywords") word_group_box.setLayout(main_v_box) self.setCentralWidget(word_group_box)
def __init__(self, parent=None): QListView.__init__(self, parent) self.setStyleSheet(''' QListView { color: FG; background: BG } QListView::item:selected { border-radius: 8px; background: HB; color: HF } '''.replace('HB', color('tab tree current background', 'palette(highlight)')).replace( 'HF', color('tab tree current foreground', 'palette(highlight-text')).replace( 'FG', color('tab tree foreground', 'palette(window-text)')).replace( 'BG', color( 'tab tree background', 'palette(window)'))) self.setFrameStyle(QFrame.Shape.NoFrame) self.viewport().setAutoFillBackground(False) self.setIconSize(QSize(16, 16)) self.setSpacing(2) self.setFocusPolicy(Qt.FocusPolicy.NoFocus) self.delegate = d = Delegate(self) self.setItemDelegate(d)
def __init__(self): QListView.__init__(self) self.setDragDropMode(QAbstractItemView.DragDropMode.InternalMove) self.setDragEnabled(True) self.setAcceptDrops(True) self.setDropIndicatorShown(True)
def dropEvent(self, event): if event.source(): QListView.dropEvent(self, event) else: m = event.mimeData() if m.hasUrls(): urls = [ url.toLocalFile() for url in m.urls() if url.isLocalFile() ] if urls: self.drop_files.emit(urls) event.acceptProposedAction()
def initUI(self): self.setWindowTitle("确认删除") self.setWindowIcon(QIcon(SRC_DIR + "delete.ico")) self.layout = QVBoxLayout() self.list_view = QListView() self.list_view.setViewMode(QListView.ViewMode.ListMode) # 列表 self.slm = QStandardItem() self.model = QStandardItemModel() max_len = 10 count = 0 for info in self.infos: if info.is_file: # 文件 self.model.appendRow( QStandardItem(set_file_icon(info.name), info.name)) else: self.model.appendRow( QStandardItem(QIcon(SRC_DIR + "folder.gif"), info.name)) self.out.append({ 'fid': info.id, 'is_file': info.is_file, 'name': info.name }) # id,文件标示, 文件名 count += 1 if max_len < len(info.name): # 使用最大文件名长度 max_len = len(info.name) self.list_view.setModel(self.model) self.lb_name = QLabel("尝试删除以下{}个文件(夹):".format(count)) self.buttonBox = QDialogButtonBox() self.buttonBox.setOrientation(Qt.Orientation.Horizontal) self.buttonBox.setStandardButtons( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText("确定") self.buttonBox.button( QDialogButtonBox.StandardButton.Cancel).setText("取消") self.layout.addWidget(self.lb_name) self.layout.addWidget(self.list_view) self.layout.addWidget(self.buttonBox) self.setLayout(self.layout) self.buttonBox.accepted.connect(self.btn_ok) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.setMinimumWidth(400) self.resize(int(max_len * 8), int(count * 34 + 60))
def setup_ui(self): self.l = l = QVBoxLayout(self) self.filter_edit = le = QLineEdit(self) le.setPlaceholderText(_('Filter the list')) l.addWidget(le) self.model = KeysModel(self.db, self) self.proxy_model = pm = QSortFilterProxyModel(self) pm.setSourceModel(self.model), pm.setFilterCaseSensitivity( Qt.CaseSensitivity.CaseInsensitive) self.view = v = QListView(self) v.setStyleSheet('QListView::item { padding: 5px }') v.setAlternatingRowColors(True) v.setModel(self.proxy_model) v.activated.connect(self.item_activated) l.addWidget(v) le.textChanged.connect(pm.setFilterFixedString) self.bb.setStandardButtons(QDialogButtonBox.StandardButton.Close) l.addWidget(self.bb) self.bb.addButton( _('Import from LastPass'), QDialogButtonBox.ButtonRole.ActionRole).clicked.connect( self.import_from_lastpass) self.bb.addButton( _('Change password'), QDialogButtonBox.ButtonRole.ActionRole).clicked.connect( self.change_password) self.bb.addButton( _('Add entry'), QDialogButtonBox.ButtonRole.ActionRole).clicked.connect( self.add_entry) self.bb.addButton( _('Remove selected'), QDialogButtonBox.ButtonRole.ActionRole).clicked.connect( self.remove_selected) self.bb.button(QDialogButtonBox.StandardButton.Close).setDefault(True)