本文整理汇总了Python中PyQt5.QtWidgets.QListView类的典型用法代码示例。如果您正苦于以下问题:Python QListView类的具体用法?Python QListView怎么用?Python QListView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QListView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *args):
QWidget.__init__(self, *args)
# create table
list_data = [1,2,3,4]
lm = MyListModel(list_data, self)
lv = QListView()
lv.setModel(lm)
# layout
layout = QVBoxLayout()
layout.addWidget(lv)
self.setLayout(layout)
示例2: __init__
def __init__(self, parent=None):
super(Window, self).__init__(parent)
model = FileListModel(self)
model.setDirPath(QLibraryInfo.location(QLibraryInfo.PrefixPath))
label = QLabel("Directory")
lineEdit = QLineEdit()
label.setBuddy(lineEdit)
view = QListView()
view.setModel(model)
self.logViewer = QTextBrowser()
self.logViewer.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred))
lineEdit.textChanged.connect(model.setDirPath)
lineEdit.textChanged.connect(self.logViewer.clear)
model.numberPopulated.connect(self.updateLog)
layout = QGridLayout()
layout.addWidget(label, 0, 0)
layout.addWidget(lineEdit, 0, 1)
layout.addWidget(view, 1, 0, 1, 2)
layout.addWidget(self.logViewer, 2, 0, 1, 2)
self.setLayout(layout)
self.setWindowTitle("Fetch More Example")
示例3: SettingWindow
class SettingWindow(QWidget):
# on_addButtonClicked=pyqtSignal()
# on_removeButtonClicked=pyqtSignal()
# on_okButtonClicked=pyqtSignal()
finished=pyqtSignal()
def __init__(self):
QWidget.__init__(self)
self.listview=QListView(self)
self.addButton=QPushButton(self)
self.removeButton=QPushButton(self)
self.resize(630,440)
self.okButton=QPushButton(self)
self.listview.setGeometry(30,30,410,351)
self.addButton.setGeometry(490,40,80,22)
self.addButton.setText("add")
self.addButton.clicked.connect(self.click_add)
self.removeButton.setGeometry(490,80,80,22)
self.removeButton.setText("remove")
self.removeButton.clicked.connect(self.click_remove)
self.okButton.setGeometry(490,150,80,22)
self.okButton.setText("ok")
self.okButton.clicked.connect(self.click_ok)
# self.aw=null
self.fresh()
def click_ok(self):
self.finished.emit()
self.close()
def click_add(self):
self.aw=AddWindow()
self.aw.show()
self.aw.okSig.connect(self.fresh)
def click_remove(self):
self.remove()
def fresh(self):
confFile=open("conf","r")
self.listModel=QStandardItemModel()
self.itemList=cPickle.load(confFile)
confFile.close()
for item in self.itemList:
itemView=QStandardItem(QIcon(item.path),item.name)
itemView.setEditable(False)
self.listModel.appendRow(itemView)
self.listview.setModel(self.listModel)
def remove(self):
index=self.listview.currentIndex().row()
self.itemList.pop(index)
self.listModel.removeRow(index)
confFile=open("conf","w")
cPickle.dump(self.itemList,confFile)
confFile.close()
示例4: __init__
def __init__(self, parent=None):
QListView.__init__(self, parent)
dndView.__init__(self, parent)
outlineBasics.__init__(self, parent)
self.setResizeMode(QListView.Adjust)
self.setWrapping(True)
self.setItemDelegate(corkDelegate())
self.setSpacing(5)
self.setVerticalScrollMode(self.ScrollPerPixel)
self.setFlow(self.LeftToRight)
self.setSelectionBehavior(self.SelectRows)
self.updateBackground()
示例5: QueryDialog
class QueryDialog(QDialog):
"""a dialog to choose an item from a query
"""
choice = pyqtSignal(str)
def __init__(self, query):
super().__init__()
self.query = query
self.create_model()
self.init_UI()
def create_model(self):
"""creates the model as QSqlQueryModel,
using the given query
"""
self.model = QSqlQueryModel()
q = QSqlQuery()
q.exec_(self.query)
self.model.setQuery(q)
def init_UI(self):
"""setup the UI
"""
layout = QVBoxLayout()
self.setLayout(layout)
self.resize(200,200)
self.title = "Choose an existing project"
self.list = QListView(self)
layout.addWidget(self.list)
self.list.setModel(self.model)
self.list.setWhatsThis("Choose a project by clicking on it")
self.btn = QPushButton("Accept", self)
layout.addWidget(self.btn)
self.btn.clicked.connect(self.on_btn_clicked)
self.btn.setWhatsThis("Click here to accept your selection (works only if a project has been selected)")
def on_btn_clicked(self):
"""when self.btn is clicked, accept the choice and emit it as self.choice
"""
selected = self.list.selectedIndexes()
if selected:
index = selected[0]
chosen = self.model.data(index, Qt.DisplayRole)
self.choice.emit(chosen)
self.close()
self.choice.emit("")
self.close()
示例6: __init__
def __init__(self, parent=None):
super(MDIHistory, self).__init__(parent)
self.setMinimumSize(QSize(200, 150))
self.setWindowTitle("PyQt5 editor test example")
lay = QVBoxLayout()
lay.setContentsMargins(0,0,0,0)
self.setLayout(lay)
self.list = QListView()
self.list.setEditTriggers(QListView.NoEditTriggers)
self.list.activated.connect(self.activated)
self.list.setAlternatingRowColors(True)
self.list.selectionChanged = self.selectionChanged
self.model = QStandardItemModel(self.list)
self.MDILine = MDILine()
self.MDILine.soft_keyboard = False
self.MDILine.line_up = self.line_up
self.MDILine.line_down = self.line_down
STATUS.connect('reload-mdi-history', self.reload)
# add widgets
lay.addWidget(self.list)
lay.addWidget(self.MDILine)
self.fp = os.path.expanduser(INFO.MDI_HISTORY_PATH)
try:
open(self.fp, 'r')
except:
open(self.fp, 'a+')
LOG.debug('MDI History file created: {}'.format(self.fp))
self.reload()
self.select_row('last')
示例7: __init__
def __init__(self, parent=None):
super(MDIHistory, self).__init__(parent)
self.setMinimumSize(QSize(300, 200))
self.setWindowTitle("PyQt5 editor test example")
lay = QVBoxLayout()
lay.setContentsMargins(0,0,0,0)
self.setLayout(lay)
self.list = QListView()
self.list.setEditTriggers(QListView.NoEditTriggers)
self.list.activated.connect(self.activated)
self.list.setAlternatingRowColors(True)
self.list.selectionChanged = self.selectionChanged
self.model = QStandardItemModel(self.list)
self.MDILine = MDILine()
self.MDILine.soft_keyboard = False
self.MDILine.line_up = self.line_up
self.MDILine.line_down = self.line_down
# add widgets
lay.addWidget(self.list)
lay.addWidget(self.MDILine)
self.reload()
示例8: setupWidgets
def setupWidgets(self):
frame = QFrame()
frameLayout = QHBoxLayout(frame)
self.piecesList = QListView()
self.piecesList.setDragEnabled(True)
self.piecesList.setViewMode(QListView.IconMode)
self.piecesList.setIconSize(QSize(60,60))
self.piecesList.setGridSize(QSize(80,80))
self.piecesList.setSpacing(10)
self.piecesList.setMovement(QListView.Snap)
self.piecesList.setAcceptDrops(True)
self.piecesList.setDropIndicatorShown(True)
self.model = PiecesModel(self)
self.piecesList.setModel(self.model)
self.puzzleWidget = PuzzleWidget()
self.puzzleWidget.puzzleCompleted.connect(self.setCompleted,
Qt.QueuedConnection)
frameLayout.addWidget(self.piecesList)
frameLayout.addWidget(self.puzzleWidget)
self.setCentralWidget(frame)
示例9: initUI
def initUI(self):
#GrBox1
GrBox=QGroupBox()
vbox = QHBoxLayout(self)
vbox.setContentsMargins(0,0,0,0)
#GrBox.setFixedHeight(60)
pathButton = QPushButton(QIcon('icons\\pack.png'),"Папка")
pathButton.setIconSize(QSize(25,25))
pathButton.setVisible(True)
pathLable=QLineEdit()
#pathLable.setReadOnly(True)
subPathCheck=QCheckBox()
subPathCheck.setText("Подпапки")
subPathCheck.setCheckState(0)
vbox.addWidget(pathLable)
vbox.addWidget(subPathCheck)
vbox.addWidget(pathButton)
GrBox.setLayout(vbox)
#/GrBox1
#FilesTable
FilesTable=QListView(self)
FilesTable.setToolTip("Список файлов, выберите нужные файлы для обработки,\nдля просмотра файла дважды щелкните по нему")
FilesTableModel = QStandardItemModel()
FilesTable.setModel(FilesTableModel)
#/FilesTable
#mainLayout
mainLayout = QVBoxLayout()
mainLayout.setContentsMargins(0,0,0,0)
mainLayout.setMenuBar(GrBox)
mainLayout.addWidget(FilesTable)
#/mainLayout
#self
self.setLayout(mainLayout)
self.path=pathLable.text()
self.pathLable=pathLable
self.subPathCheck=subPathCheck
self.FilesTableModel = FilesTableModel
#/self
#connections
pathLable.textChanged.connect(self.setPath)
pathButton.clicked.connect(self.selectPath)
subPathCheck.clicked.connect(self.setPath)
FilesTableModel.itemChanged.connect(self.ChangeFilesList)
FilesTable.doubleClicked.connect(self.openFile)
示例10: ListScrollArea
class ListScrollArea(QVBoxLayout):
def __init__(self, parent):
QVBoxLayout.__init__(self, parent)
self.scroll_area = QScrollArea()
# A ListView is a widget, instead of a layout, so there should be no need for additional containers
self.list_view = QListView()
self.scroll_area.setWidget(self.list_view)
self.addWidget(self.list_view)
self.view_model = QStringListModel()
self.list_view.setModel(self.view_model)
def add_item_by_string(self, value):
current_values = self.view_model.stringList()
if value not in current_values:
current_values.append(value)
self.view_model.setStringList(current_values)
def remove_item_by_string(self, value):
current_values = self.view_model.stringList()
if value in current_values:
current_values.remove(value)
self.view_model.setStringList(current_values)
def clear_all(self):
self.view_model.setStringList([])
def get_currently_selected_item(self):
currently_selected_item_index = self.view_model.currentIndex()
currently_selected_item_text = str(self.list_view.data(currently_selected_item_index))
return currently_selected_item_text
def get_item(self, index):
current_values = self.view_model.stringList()
if index < len(current_values):
return current_values[index]
return None
def get_num_items(self):
return len(self.view_model.stringList())
示例11: __init__
def __init__(self, parent):
super(PatchPanel, self).__init__()
self.ola = parent.ola
self.parent = parent
self.device_selected = None
self.universe = None
grid = QGridLayout()
self.inputs_model = PortList(self, 'input_mode')
self.outputs_model = PortList(self, 'output_mode')
self.devices = QListView()
self.devices_model = DeviceList(self)
self.devices.setModel(self.devices_model)
self.inputs = QListView()
self.inputs.setModel(self.inputs_model)
self.inputs.setMinimumHeight(400)
self.inputs.setMinimumHeight(120)
self.outputs = QListView()
self.outputs.setModel(self.outputs_model)
self.outputs.setMinimumHeight(400)
self.outputs.setMinimumHeight(120)
# Universe Selected Change
self.devices.selectionModel().selectionChanged.connect(self.device_selection_changed)
devices_label = QLabel('Devices')
grid.addWidget(devices_label, 0, 0, 1, 1)
grid.addWidget(self.devices, 1, 0, 21, 1)
inputs_label = QLabel('Inputs')
grid.addWidget(inputs_label, 0, 1, 1, 1)
grid.addWidget(self.inputs, 1, 1, 10, 1)
outputs_label = QLabel('Outputs')
grid.addWidget(outputs_label, 11, 1, 1, 1)
grid.addWidget(self.outputs, 12, 1, 10, 1)
grid.setSpacing(5)
self.setLayout(grid)
示例12: __init__
def __init__(self, qpart, model):
QListView.__init__(self, qpart.viewport())
# ensure good selected item background on Windows
palette = self.palette()
palette.setColor(palette.Inactive, palette.Highlight, palette.color(palette.Active, palette.Highlight))
self.setPalette(palette)
self.setAttribute(Qt.WA_DeleteOnClose)
self.setItemDelegate(HTMLDelegate(self))
self._qpart = qpart
self.setFont(qpart.font())
self.setCursor(QCursor(Qt.PointingHandCursor))
self.setFocusPolicy(Qt.NoFocus)
self.setModel(model)
self._selectedIndex = -1
# if cursor moved, we shall close widget, if its position (and model) hasn't been updated
self._closeIfNotUpdatedTimer = QTimer(self)
self._closeIfNotUpdatedTimer.setInterval(200)
self._closeIfNotUpdatedTimer.setSingleShot(True)
self._closeIfNotUpdatedTimer.timeout.connect(self._afterCursorPositionChanged)
qpart.installEventFilter(self)
qpart.cursorPositionChanged.connect(self._onCursorPositionChanged)
self.clicked.connect(lambda index: self.itemSelected.emit(index.row()))
self.updateGeometry()
self.show()
qpart.setFocus()
示例13: __init__
def __init__(self, parent=None):
self.parent = parent
self.parent.statusbar.showMessage("Keep Columns started...")
QWidget.__init__(self,parent)
self.ui = gui.keepColumnUi()
self.ui.setupUi(self)
self.columns = []
self.batch_files = filedialog.askopenfilenames(parent=root, title='Choose the file(s) you want to modify')
if len(self.batch_files) == 0:
self.close()
return
self.parent.statusbar.showMessage("Checking column validity...")
#extract columns
for item in self.batch_files:
self.columns.append(helpers.extract_columns(item))
#check to see if all columns are equal in all the datasets
if not helpers.are_columns_same(self.columns):
if not helpers.columns_not_equal_message(self):
self.close()
return
#list of items to check from
self.model = QStandardItemModel()
try:
for col in self.columns[0]:
item = QStandardItem(col)
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
item.setData(QVariant(Qt.Unchecked), Qt.CheckStateRole)
self.model.appendRow(item)
except IndexError:
pass
self.list = QListView(self)
self.list.setModel(self.model)
self.list.setGeometry(10, 60, 380, 430)
self.ui.removeBtn.clicked.connect(self.keep)
self.ui.closeBtn.clicked.connect(self.close)
self.parent.statusbar.showMessage("Welcome back!")
self.show()
示例14: _setupUi
def _setupUi(self):
self.setWindowTitle(tr("Re-Prioritize duplicates"))
self.resize(700, 400)
#widgets
msg = tr(
"Add criteria to the right box and click OK to send the dupes that correspond the "
"best to these criteria to their respective group's "
"reference position. Read the help file for more information."
)
self.promptLabel = QLabel(msg)
self.promptLabel.setWordWrap(True)
self.categoryCombobox = QComboBox()
self.criteriaListView = QListView()
self.addCriteriaButton = QPushButton(self.style().standardIcon(QStyle.SP_ArrowRight), "")
self.removeCriteriaButton = QPushButton(self.style().standardIcon(QStyle.SP_ArrowLeft), "")
self.prioritizationListView = QListView()
self.prioritizationListView.setAcceptDrops(True)
self.prioritizationListView.setDragEnabled(True)
self.prioritizationListView.setDragDropMode(QAbstractItemView.InternalMove)
self.prioritizationListView.setSelectionBehavior(QAbstractItemView.SelectRows)
self.buttonBox = QDialogButtonBox()
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
# layout
self.mainLayout = QVBoxLayout(self)
self.mainLayout.addWidget(self.promptLabel)
self.splitter = QSplitter()
sp = self.splitter.sizePolicy()
sp.setVerticalPolicy(QSizePolicy.Expanding)
self.splitter.setSizePolicy(sp)
self.leftSide = QWidget()
self.leftWidgetsLayout = QVBoxLayout()
self.leftWidgetsLayout.addWidget(self.categoryCombobox)
self.leftWidgetsLayout.addWidget(self.criteriaListView)
self.leftSide.setLayout(self.leftWidgetsLayout)
self.splitter.addWidget(self.leftSide)
self.rightSide = QWidget()
self.rightWidgetsLayout = QHBoxLayout()
self.addRemoveButtonsLayout = QVBoxLayout()
self.addRemoveButtonsLayout.addItem(verticalSpacer())
self.addRemoveButtonsLayout.addWidget(self.addCriteriaButton)
self.addRemoveButtonsLayout.addWidget(self.removeCriteriaButton)
self.addRemoveButtonsLayout.addItem(verticalSpacer())
self.rightWidgetsLayout.addLayout(self.addRemoveButtonsLayout)
self.rightWidgetsLayout.addWidget(self.prioritizationListView)
self.rightSide.setLayout(self.rightWidgetsLayout)
self.splitter.addWidget(self.rightSide)
self.mainLayout.addWidget(self.splitter)
self.mainLayout.addWidget(self.buttonBox)
示例15: __init__
def __init__(self, *args):
# Invoke parent init
QListView.__init__(self, *args)
# Get a reference to the window object
self.app = get_app()
self.win = args[0]
# Get Model data
self.title_model = TitlesModel()
# Setup header columns
self.setModel(self.title_model.model)
self.setIconSize(QSize(131, 108))
self.setGridSize(QSize(102, 92))
self.setViewMode(QListView.IconMode)
self.setResizeMode(QListView.Adjust)
self.setUniformItemSizes(True)
self.setWordWrap(True)
self.setTextElideMode(Qt.ElideRight)
# Refresh view
self.refresh_view()