Python PyQt5.QtWidgets 模块,QListView() 实例源码

我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用PyQt5.QtWidgets.QListView()

项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def init_widget(self):
        self.setWindowTitle("Hello World")
        widget_laytout = QBoxLayout(QBoxLayout.LeftToRight)

        group = QGroupBox()
        box = QBoxLayout(QBoxLayout.TopToBottom)
        group.setLayout(box)
        group.setTitle("Buttons")
        widget_laytout.addWidget(group)

        fruits = ["Buttons in GroupBox", "TextBox in GroupBox", "Label in GroupBox", "TextEdit"]
        view = QListView(self)
        model = QStandardItemModel()
        for f in fruits:
            model.appendRow(QStandardItem(f))
        view.setModel(model)
        box.addWidget(view)

        self.stk_w.addWidget(Widget_1())
        self.stk_w.addWidget(Widget_2())
        self.stk_w.addWidget(Widget_3())
        self.stk_w.addWidget(QTextEdit())

        widget_laytout.addWidget(self.stk_w)
        self.setLayout(widget_laytout)

        # ??? ?? ??
        view.clicked.connect(self.slot_clicked_item)
项目:plexdesktop    作者:coryo    | 项目源码 | 文件源码
def toggle_view_mode(self):
        if self.viewMode() == QtWidgets.QListView.ListMode:
            self.setItemDelegate(self.tile_delegate)
            self.setViewMode(QtWidgets.QListView.IconMode)
            bg_vertical = True
            self.setSpacing(4)
            self.icon_size(min(self.last_icon_size.height() * 2,
                               self.max_icon_size))
        else:
            self.setItemDelegate(self.list_delegate)
            self.setViewMode(QtWidgets.QListView.ListMode)
            bg_vertical = False
            self.setSpacing(0)
            self.icon_size(max(self.last_icon_size.height() / 2,
                               self.min_icon_size))
        self.setAlternatingRowColors(not bg_vertical)
        self.viewModeChanged.emit()
        if self.selectedIndexes():
            self.scrollTo(self.selectedIndexes()[0],
                          QtWidgets.QAbstractItemView.PositionAtCenter)
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def __init__(self):
        QWidget.__init__(self, flags=Qt.Widget)
        self.setWindowTitle("ItemView QListView")
        self.setFixedWidth(210)
        self.setFixedHeight(100)

        fruits = [
            {"name": "banana", "color": "yellow", "bg_color": "yellow"},
            {"name": "apple", "color": "red", "bg_color": "red"},
            {"name": "pear", "color": "green", "bg_color": "gray"},
        ]

        view = QListView(self)
        view.setEditTriggers(QAbstractItemView.DoubleClicked)

        model = UserModel(fruits)
        view.setModel(model)
项目:Visualization    作者:nwrush    | 项目源码 | 文件源码
def setupUi(self, topicsList):
        topicsList.setObjectName("topicsList")
        topicsList.resize(642, 730)
        self.verticalLayout = QtWidgets.QVBoxLayout(topicsList)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(topicsList)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.filterText = QtWidgets.QLineEdit(topicsList)
        self.filterText.setObjectName("filterText")
        self.verticalLayout.addWidget(self.filterText)
        self.listWidget = QtWidgets.QListView(topicsList)
        self.listWidget.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
        self.listWidget.setObjectName("listWidget")
        self.verticalLayout.addWidget(self.listWidget)

        self.retranslateUi(topicsList)
        QtCore.QMetaObject.connectSlotsByName(topicsList)
项目:PyQt5-reorderable-list-model    作者:d1vanov    | 项目源码 | 文件源码
def __init__(self, parent=None):
        QtWidgets.QMainWindow.__init__(self, parent)
        self.model = ReorderableListModel()
        self.selectionModel = SelectionModel(self.model)
        self.model.dragDropFinished.connect(self.selectionModel.onModelItemsReordered)
        self.view = QtWidgets.QListView()
        self.view.setModel(self.model)
        self.view.setSelectionModel(self.selectionModel)
        self.view.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
        self.view.setDragDropOverwriteMode(False)
        self.setCentralWidget(self.view)
项目:acbDecrypter    作者:Rieksee    | 项目源码 | 文件源码
def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(830, 333)
        Form.setMinimumSize(QtCore.QSize(700, 300))
        self.gridLayout = QtWidgets.QGridLayout(Form)
        self.gridLayout.setObjectName("gridLayout")
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setSpacing(20)
        self.verticalLayout.setObjectName("verticalLayout")
        self.listView = QtWidgets.QListView(Form)
        self.listView.setObjectName("listView")
        self.verticalLayout.addWidget(self.listView)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setSpacing(30)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setMinimumSize(QtCore.QSize(0, 50))
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout.addWidget(self.pushButton)
        self.pushButton_2 = QtWidgets.QPushButton(Form)
        self.pushButton_2.setMinimumSize(QtCore.QSize(0, 50))
        self.pushButton_2.setMaximumSize(QtCore.QSize(230, 16777215))
        self.pushButton_2.setObjectName("pushButton_2")
        self.horizontalLayout.addWidget(self.pushButton_2)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)

        self.retranslateUi(Form)
        self.listView.clicked['QModelIndex'].connect(Form.key_selected)
        self.pushButton.clicked.connect(Form.enter)
        self.pushButton_2.clicked.connect(Form.not_use_key)
        QtCore.QMetaObject.connectSlotsByName(Form)
项目:COMTool    作者:Neutree    | 项目源码 | 文件源码
def __init__(self):
        QComboBox.__init__(self)
        self.setView(QListView())
        return
项目:plexdesktop    作者:coryo    | 项目源码 | 文件源码
def __init__(self, parent=None, server=None):
        super().__init__(parent)
        self._model = ListModel(self)
        self.setModel(self._model)
        self._last_count = 0
        self.list_delegate = plexdesktop.delegates.ListDelegate(self)
        self.tile_delegate = plexdesktop.delegates.TileDelegateUniform(self)
        self.setItemDelegate(self.list_delegate)
        self.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
        self.setResizeMode(QtWidgets.QListView.Adjust)
        self.icon_size(32)
        self.setAlternatingRowColors(True)
        self.setUniformItemSizes(True)
        self.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)
        # self.setWrapping(True)
        # self.setBatchSize(50)
        # self.setLayoutMode(QtWidgets.QListView.Batched)

        self.min_icon_size = self.list_delegate.title_font_metrics.height()
        self.max_icon_size = 300

        self.doubleClicked.connect(self.double_click)
        self.container_request.connect(self.model().fetch_container)
        self.customContextMenuRequested.connect(self.context_menu)
        self.itemDoubleClicked.connect(self.item_double_clicked)
        self.itemSelectionChanged.connect(self.selection_changed)
        # Model signals
        self.model().working.connect(self.working.emit)
        self.model().done.connect(self.finished.emit)
        self.model().done.connect(self.check_view_mode)
        self.model().new_container_titles.connect(self.new_titles.emit)

        self.location = plexdesktop.utils.Location.home()
        self.current_server = server
        self.history = [(self.current_server, self.location)]
        self.history_cursor = -1

        self.forced_toggle = False
项目:plexdesktop    作者:coryo    | 项目源码 | 文件源码
def check_view_mode(self):
        if self.model().container:
            group = self.model().container.data.get('viewGroup')
            if group == 'photo':
                if self.viewMode() == QtWidgets.QListView.ListMode:
                    self.forced_toggle = True
                    self.toggle_view_mode()
            else:
                if self.forced_toggle and self.viewMode() == QtWidgets.QListView.IconMode:
                    self.toggle_view_mode()
                    self.forced_toggle = False
项目:ETS2Autopilot    作者:BrunoTh    | 项目源码 | 文件源码
def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(462, 431)
        self.list_images = QtWidgets.QListView(MainWindow)
        self.list_images.setGeometry(QtCore.QRect(10, 10, 180, 371))
        self.list_images.setObjectName("list_images")
        self.b_delete = QtWidgets.QPushButton(MainWindow)
        self.b_delete.setGeometry(QtCore.QRect(10, 390, 180, 30))
        self.b_delete.setObjectName("b_delete")
        self.captured_image = QtWidgets.QLabel(MainWindow)
        self.captured_image.setGeometry(QtCore.QRect(200, 10, 250, 100))
        self.captured_image.setFrameShape(QtWidgets.QFrame.Box)
        self.captured_image.setText("")
        self.captured_image.setObjectName("captured_image")
        self.b_save = QtWidgets.QPushButton(MainWindow)
        self.b_save.setGeometry(QtCore.QRect(360, 390, 95, 30))
        self.b_save.setObjectName("b_save")
        self.groupBox = QtWidgets.QGroupBox(MainWindow)
        self.groupBox.setGeometry(QtCore.QRect(200, 180, 141, 151))
        self.groupBox.setObjectName("groupBox")
        self.b_noIndicator = QtWidgets.QPushButton(self.groupBox)
        self.b_noIndicator.setGeometry(QtCore.QRect(10, 30, 121, 30))
        self.b_noIndicator.setObjectName("b_noIndicator")
        self.b_leftIndicator = QtWidgets.QPushButton(self.groupBox)
        self.b_leftIndicator.setGeometry(QtCore.QRect(10, 70, 121, 30))
        self.b_leftIndicator.setObjectName("b_leftIndicator")
        self.b_rightIndicator = QtWidgets.QPushButton(self.groupBox)
        self.b_rightIndicator.setGeometry(QtCore.QRect(10, 110, 121, 30))
        self.b_rightIndicator.setObjectName("b_rightIndicator")

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
项目:bubblesub    作者:rr-    | 项目源码 | 文件源码
def __init__(self, api, model, selection_model, parent):
        super().__init__(parent)
        self._api = api
        selection_model.selectionChanged.connect(self._on_selection_change)

        self._styles_list_view = QtWidgets.QListView(self)
        self._styles_list_view.setModel(model)
        self._styles_list_view.setSelectionModel(selection_model)

        self._add_button = QtWidgets.QPushButton('Add', self)
        self._add_button.clicked.connect(self._on_add_button_click)
        self._remove_button = QtWidgets.QPushButton('Remove', self)
        self._remove_button.setEnabled(False)
        self._remove_button.clicked.connect(self._on_remove_button_click)
        self._duplicate_button = QtWidgets.QPushButton('Duplicate', self)
        self._duplicate_button.setEnabled(False)
        self._duplicate_button.clicked.connect(self._on_duplicate_button_click)
        self._move_up_button = QtWidgets.QPushButton('Move up', self)
        self._move_up_button.setEnabled(False)
        self._move_up_button.clicked.connect(self._on_move_up_button_click)
        self._move_down_button = QtWidgets.QPushButton('Move down', self)
        self._move_down_button.setEnabled(False)
        self._move_down_button.clicked.connect(self._on_move_down_button_click)
        self._rename_button = QtWidgets.QPushButton('Rename', self)
        self._rename_button.setEnabled(False)
        self._rename_button.clicked.connect(self._on_rename_button_click)

        strip = QtWidgets.QWidget(self)
        layout = QtWidgets.QGridLayout(strip, margin=0)
        layout.addWidget(self._add_button, 0, 0)
        layout.addWidget(self._remove_button, 0, 1)
        layout.addWidget(self._duplicate_button, 0, 2)
        layout.addWidget(self._move_up_button, 1, 0)
        layout.addWidget(self._move_down_button, 1, 1)
        layout.addWidget(self._rename_button, 1, 2)

        layout = QtWidgets.QVBoxLayout(self, margin=0)
        layout.addWidget(self._styles_list_view)
        layout.addWidget(strip)
项目:bubblesub    作者:rr-    | 项目源码 | 文件源码
def __init__(self, api, main_window, dictionary):
        super().__init__(main_window)
        self._main_window = main_window
        self._api = api
        self._dictionary = dictionary
        self._lines_to_spellcheck = api.subs.selected_lines

        self._mispelt_text_edit = QtWidgets.QLineEdit(self, readOnly=True)
        self._replacement_text_edit = QtWidgets.QLineEdit(self)
        self._suggestions_list_view = QtWidgets.QListView(self)
        self._suggestions_list_view.setModel(QtGui.QStandardItemModel())
        self._suggestions_list_view.clicked.connect(self._on_suggestion_click)

        box = QtWidgets.QWidget(self)
        layout = QtWidgets.QVBoxLayout(box)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(QtWidgets.QLabel('Mispelt word:', self))
        layout.addWidget(self._mispelt_text_edit)
        layout.addWidget(QtWidgets.QLabel('Replacement:', self))
        layout.addWidget(self._replacement_text_edit)
        layout.addWidget(QtWidgets.QLabel('Suggestions:', self))
        layout.addWidget(self._suggestions_list_view)

        strip = QtWidgets.QDialogButtonBox(
            self, orientation=QtCore.Qt.Vertical)
        self.add_btn = strip.addButton('Add to dictionary', strip.ActionRole)
        self.ignore_btn = strip.addButton('Ignore', strip.ActionRole)
        self.ignore_all_btn = strip.addButton('Ignore all', strip.ActionRole)
        self.replace_btn = strip.addButton('Replace', strip.ActionRole)
        strip.addButton('Cancel', strip.RejectRole)
        strip.clicked.connect(self.action)
        strip.rejected.connect(self.reject)

        layout = QtWidgets.QHBoxLayout(self, spacing=24)
        layout.addWidget(box)
        layout.addWidget(strip)

        if self._next():
            self.exec_()
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def __init__(self):
        QWidget.__init__(self, flags=Qt.Widget)
        self.setWindowTitle("ItemView QListView")
        self.setFixedWidth(210)
        self.setFixedHeight(100)

        fruits = [
            {"name": "banana", "color": "yellow", "bg_color": "yellow"},
            {"name": "apple", "color": "red", "bg_color": "red"},
            {"name": "pear", "color": "green", "bg_color": "gray"},
        ]

        view = QListView(self)
        model = UserModel(fruits)
        view.setModel(model)
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def __init__(self):
        QWidget.__init__(self, flags=Qt.Widget)
        self.setWindowTitle("ItemView QListView")
        self.setFixedHeight(100)

        fruits = ["banana", "apple", "melon", "pear"]

        view = QListView(self)
        model = QStandardItemModel()
        for f in fruits:
            model.appendRow(QStandardItem(f))
        view.setModel(model)
项目:binja-ui-api    作者:nbsdx    | 项目源码 | 文件源码
def FunctionWindow():
    app = _app()

    views = [x for x in app.allWidgets() if x.__class__ is QtWidgets.QListView]

    for view in views:
        if view.parent().__class__ is QtWidgets.QWidget:
            if view.parent().parent().__class__ is QtWidgets.QSplitter:
                return view.parent()

    return None
项目:binja-ui-api    作者:nbsdx    | 项目源码 | 文件源码
def TabWidget():
    app = _app()

    views = [x for x in app.allWidgets() if x.__class__ is QtWidgets.QListView]

    for view in views:
        if view.parent().__class__ is QtWidgets.QStackedWidget:
            if view.parent().parent().__class__ is QtWidgets.QTabWidget:
                return view.parent().parent()

    return None
项目:FIRST-plugin-ida    作者:vrtadmin    | 项目源码 | 文件源码
def populate_main_form(self):
        list_view = QtWidgets.QListView()
        list_view.setFixedWidth(115)
        list_view.setModel(self.views_model)

        select = QtCore.QItemSelectionModel.Select
        list_view.selectionModel().select(self.views_model.createIndex(0, 0), select)
        list_view.clicked.connect(self.view_clicked)

        current_view = QtWidgets.QWidget()
        view = self.view_about()
        if not view:
            view = QtWidgets.QBoxLayout()
        current_view.setLayout(view)

        self.splitter = QtWidgets.QSplitter(Qt.Horizontal)
        self.splitter.addWidget(list_view)

        self.splitter.addWidget(current_view)
        self.splitter.setChildrenCollapsible(False)
        self.splitter.show()

        outer_layout = QtWidgets.QHBoxLayout()
        outer_layout.addWidget(self.splitter)

        self.parent.setLayout(outer_layout)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def setupUi(self, FramePlugins):
        FramePlugins.setObjectName("FramePlugins")
        FramePlugins.resize(806, 683)
        self.verticalLayout_3 = QtWidgets.QVBoxLayout(FramePlugins)
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.label = QtWidgets.QLabel(FramePlugins)
        self.label.setObjectName("label")
        self.verticalLayout_2.addWidget(self.label)
        self.listViewPlugins = QtWidgets.QListView(FramePlugins)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.MinimumExpanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.listViewPlugins.sizePolicy().hasHeightForWidth())
        self.listViewPlugins.setSizePolicy(sizePolicy)
        self.listViewPlugins.setObjectName("listViewPlugins")
        self.verticalLayout_2.addWidget(self.listViewPlugins)
        self.horizontalLayout.addLayout(self.verticalLayout_2)
        self.verticalLayout = QtWidgets.QVBoxLayout()
        self.verticalLayout.setObjectName("verticalLayout")
        self.label_2 = QtWidgets.QLabel(FramePlugins)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
        self.label_2.setSizePolicy(sizePolicy)
        self.label_2.setObjectName("label_2")
        self.verticalLayout.addWidget(self.label_2)
        self.txtEditPluginDescription = QtWidgets.QTextEdit(FramePlugins)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.txtEditPluginDescription.sizePolicy().hasHeightForWidth())
        self.txtEditPluginDescription.setSizePolicy(sizePolicy)
        self.txtEditPluginDescription.setReadOnly(True)
        self.txtEditPluginDescription.setPlaceholderText("")
        self.txtEditPluginDescription.setObjectName("txtEditPluginDescription")
        self.verticalLayout.addWidget(self.txtEditPluginDescription)
        self.horizontalLayout.addLayout(self.verticalLayout)
        self.verticalLayout_3.addLayout(self.horizontalLayout)
        self.groupBoxSettings = QtWidgets.QGroupBox(FramePlugins)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.groupBoxSettings.sizePolicy().hasHeightForWidth())
        self.groupBoxSettings.setSizePolicy(sizePolicy)
        self.groupBoxSettings.setMaximumSize(QtCore.QSize(16777215, 16777215))
        self.groupBoxSettings.setObjectName("groupBoxSettings")
        self.verticalLayout_3.addWidget(self.groupBoxSettings)

        self.retranslateUi(FramePlugins)
        QtCore.QMetaObject.connectSlotsByName(FramePlugins)