本文整理汇总了Python中PySide.QtGui.QTableView.setSelectionMode方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setSelectionMode方法的具体用法?Python QTableView.setSelectionMode怎么用?Python QTableView.setSelectionMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTableView
的用法示例。
在下文中一共展示了QTableView.setSelectionMode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setupTabs
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setSelectionMode [as 别名]
def setupTabs(self):
""" Setup the various tabs in the AddressWidget. """
groups = ["ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "VW", "XYZ"]
for group in groups:
proxyModel = QSortFilterProxyModel(self)
proxyModel.setSourceModel(self.tableModel)
proxyModel.setDynamicSortFilter(True)
tableView = QTableView()
tableView.setModel(proxyModel)
tableView.setSortingEnabled(True)
tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
tableView.horizontalHeader().setStretchLastSection(True)
tableView.verticalHeader().hide()
tableView.setEditTriggers(QAbstractItemView.NoEditTriggers)
tableView.setSelectionMode(QAbstractItemView.SingleSelection)
# This here be the magic: we use the group name (e.g. "ABC") to
# build the regex for the QSortFilterProxyModel for the group's
# tab. The regex will end up looking like "^[ABC].*", only
# allowing this tab to display items where the name starts with
# "A", "B", or "C". Notice that we set it to be case-insensitive.
reFilter = "^[%s].*" % group
proxyModel.setFilterRegExp(QRegExp(reFilter, Qt.CaseInsensitive))
proxyModel.setFilterKeyColumn(0) # Filter on the "name" column
proxyModel.sort(0, Qt.AscendingOrder)
tableView.selectionModel().selectionChanged.connect(self.selectionChanged)
self.addTab(tableView, group)
示例2: RunnerDialog
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setSelectionMode [as 别名]
class RunnerDialog(QDialog):
options_added = Signal(Options)
options_running = Signal(Options)
options_simulated = Signal(Options)
options_error = Signal(Options, Exception)
results_saved = Signal(Results, str)
results_error = Signal(Results, Exception)
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setWindowTitle('Runner')
self.setMinimumWidth(750)
# Runner
self._runner = None
self._running_timer = QTimer()
self._running_timer.setInterval(500)
# Widgets
self._dlg_progress = QProgressDialog()
self._dlg_progress.setRange(0, 100)
self._dlg_progress.setModal(True)
self._dlg_progress.hide()
lbl_outputdir = QLabel("Output directory")
self._txt_outputdir = DirBrowseWidget()
max_workers = cpu_count() #@UndefinedVariable
lbl_workers = QLabel('Number of workers')
self._spn_workers = QSpinBox()
self._spn_workers.setRange(1, max_workers)
self._spn_workers.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
lbl_max_workers = QLabel('(max: %i)' % max_workers)
self._chk_overwrite = QCheckBox("Overwrite existing results in output directory")
self._chk_overwrite.setChecked(True)
self._lbl_available = QLabel('Available')
self._lst_available = QListView()
self._lst_available.setModel(_AvailableOptionsListModel())
self._lst_available.setSelectionMode(QListView.SelectionMode.MultiSelection)
tlb_available = QToolBar()
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
tlb_available.addWidget(spacer)
act_open = tlb_available.addAction(getIcon("document-open"), "Open")
act_open.setShortcut(QKeySequence.Open)
tlb_available.addSeparator()
act_remove = tlb_available.addAction(getIcon("list-remove"), "Remove")
act_clear = tlb_available.addAction(getIcon("edit-clear"), "Clear")
self._btn_addtoqueue = QPushButton(getIcon("go-next"), "")
self._btn_addtoqueue.setToolTip("Add to queue")
self._btn_addtoqueue.setEnabled(False)
self._btn_addalltoqueue = QPushButton(getIcon("go-last"), "")
self._btn_addalltoqueue.setToolTip("Add all to queue")
self._btn_addalltoqueue.setEnabled(False)
self._lbl_options = QLabel('Queued/Running/Completed')
self._tbl_options = QTableView()
self._tbl_options.setModel(_StateOptionsTableModel())
self._tbl_options.setItemDelegate(_StateOptionsItemDelegate())
self._tbl_options.setSelectionMode(QListView.SelectionMode.NoSelection)
self._tbl_options.setColumnWidth(1, 60)
self._tbl_options.setColumnWidth(2, 80)
header = self._tbl_options.horizontalHeader()
header.setResizeMode(0, QHeaderView.Interactive)
header.setResizeMode(1, QHeaderView.Fixed)
header.setResizeMode(2, QHeaderView.Fixed)
header.setResizeMode(3, QHeaderView.Stretch)
self._btn_start = QPushButton(getIcon("media-playback-start"), "Start")
self._btn_cancel = QPushButton("Cancel")
self._btn_cancel.setEnabled(False)
self._btn_close = QPushButton("Close")
self._btn_import = QPushButton("Import")
self._btn_import.setEnabled(False)
# Layouts
layout = QVBoxLayout()
sublayout = QGridLayout()
sublayout.addWidget(lbl_outputdir, 0, 0)
sublayout.addWidget(self._txt_outputdir, 0, 1)
sublayout.addWidget(lbl_workers, 1, 0)
subsublayout = QHBoxLayout()
subsublayout.addWidget(self._spn_workers)
subsublayout.addWidget(lbl_max_workers)
sublayout.addLayout(subsublayout, 1, 1)
layout.addLayout(sublayout)
sublayout.addWidget(self._chk_overwrite, 2, 0, 1, 3)
#.........这里部分代码省略.........
示例3: ModelTableWidget
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setSelectionMode [as 别名]
#.........这里部分代码省略.........
return False
row = index.row()
self._models[row] = value
self.dataChanged.emit(index, index)
return True
def insertRows(self, row, count=1, parent=None):
if parent is None:
parent = QModelIndex()
self.beginInsertRows(parent, row, row + count - 1)
for _ in range(count):
self._models.insert(row, None)
self.endInsertRows()
return True
def removeRows(self, row, count=1, parent=None):
if parent is None:
parent = QModelIndex()
self.beginRemoveRows(parent, row, row + count - 1)
for index in reversed(range(row, row + count)):
self._models.pop(index)
self.endRemoveRows()
return True
def append(self, model):
self.insert(self.rowCount(), model)
def insert(self, index, model):
self.insertRows(index)
self.setData(self.createIndex(index, 0), model)
def remove(self, model):
index = self._models.index(model)
self.removeRows(index)
def clear(self):
self.removeRows(0, self.rowCount())
def models(self):
models = set(self._models)
models.discard(None)
return models
def model(self, index):
return self._models[index.row()]
def __init__(self, parent=None):
QWidget.__init__(self, parent)
# Variables
model = self._ModelTableModel()
# Widgets
self._tbl_models = QTableView()
self._tbl_models.setModel(model)
header = self._tbl_models.horizontalHeader()
header.setResizeMode(QHeaderView.Stretch)
policy = self._tbl_models.sizePolicy()
policy.setVerticalStretch(True)
self._tbl_models.setSizePolicy(policy)
self._tbl_models.setSelectionMode(QTableView.SelectionMode.MultiSelection)
# Layouts
layout = QVBoxLayout()
layout.addWidget(self._tbl_models)
self.setLayout(layout)
# Signals
model.dataChanged.connect(self.dataChanged)
def addModel(self, model):
self._tbl_models.model().append(model)
def addModels(self, models):
for model in models:
self.addModel(model)
def removeModel(self, model):
self._tbl_models.model().remove(model)
def clear(self):
self._tbl_models.model().clear()
def models(self):
return self._tbl_models.model().models()
def currentModels(self):
tbl_model = self._tbl_models.model()
models = []
for index in self._tbl_models.selectionModel().selection().indexes():
models.append(tbl_model.model(index))
return models