本文整理汇总了Python中PyQt5.QtWidgets.QTableView.selectRow方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.selectRow方法的具体用法?Python QTableView.selectRow怎么用?Python QTableView.selectRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QTableView
的用法示例。
在下文中一共展示了QTableView.selectRow方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ZoteroTableWidget
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import selectRow [as 别名]
#.........这里部分代码省略.........
main_layout.addWidget(self.view)
self.setLayout(main_layout)
# Signals section.
self.filter_edit.textChanged.connect(proxy_model.setFilterFixedString)
self.refresh_thread.started.connect(self.refresh_started)
self.refresh_thread.finished.connect(self.refresh_finished)
# def __del__(self):
# # FIXME Delayed refactoring. Not called when application is closed. Incorrect parent use?
# # NB: Exiting the program when another thread is still busy is a programming error.
# # NB: Call QThread::quit() if the thread has an event loop.
# print("DEBUG: ZoteroTableWidget.__del__()")
# # TODO Display an information dialog.
# self.refresh_thread.wait()
# print("DEBUG: ZoteroRefreshThread.wait() returned")
# Slots section.
@pyqtSlot()
def refresh_database(self):
"""Start the thread refreshing the Zotero data.
If the thread is already running, it is not restarted.
"""
self.refresh_thread.start()
@pyqtSlot()
def refresh_started(self):
"""Disable the Zotero widget when the thread refreshing its data runs.
Disable handling of keyboard/mouse events to ensure a thread-safe refresh.
"""
# TODO Display an information on top of the disabled widget.
self.setDisabled(True)
@pyqtSlot()
def refresh_finished(self):
"""Enable the Zotero widget when the thread refreshing its data finishes.
Reset the selection model of the view in case of new/deleted references.
Enable again the handling of keyboard/mouse events.
"""
self.view.selectionModel().reset()
self.setEnabled(True)
@pyqtSlot()
def add_reference(self):
"""Display the form for and handle the creation of a new reference."""
dialog = ZoteroReferenceDialog(self._zotero.reference_templates, self)
dialog.setWindowTitle("Zotero reference creation")
dialog.select_reference_type("journalArticle")
# NB: exec() always pops up the dialog as modal.
if dialog.exec():
reference_data = dialog.reference_data()
# FIXME DEBUG.
# print("\n")
# print("REFERENCE DATA: " + repr(reference_data))
# /FIXME DEBUG.
# TODO Implement an offline mode. Catch PyZoteroError.
reference = self._zotero.create_distant_reference(reference_data)
source_index = self.view.model().sourceModel().add_reference(reference)
proxy_index = self.view.model().mapFromSource(source_index)
self.view.selectRow(proxy_index.row())
@pyqtSlot()
def edit_reference(self):
"""Display the form for and handle the edition of the selected reference."""
selected = self.view.selectionModel().currentIndex()
if selected.isValid():
row = self.view.model().mapToSource(selected).row()
# FIXME DEBUG.
# print("\n")
# print("TITLE: " + self.zotero.reference_title(row))
# print("SOURCE ROW NB: " + str(row))
# /FIXME DEBUG.
reference_key = self._zotero.reference_key(row)
# TODO Refresh local when distant is different and 'Cancel' clicked.
# TODO Display an information dialog when local and distant are different.
# TODO Implement an offline mode. Catch PyZoteroError.
reference = self._zotero.get_reference(reference_key)
dialog = ZoteroReferenceDialog(self._zotero.reference_templates, self)
dialog.setWindowTitle("Zotero reference edition")
dialog.load_reference_data(reference["data"])
# NB: exec() always pops up the dialog as modal.
if dialog.exec():
reference["data"] = dialog.reference_data()
# FIXME DEBUG.
# print("\n")
# print("REFERENCE DATA: " + repr(reference["data"]))
# /FIXME DEBUG.
# TODO Implement an offline mode. Catch PyZoteroError.
self._zotero.update_distant_reference(reference)
# TODO Implement an offline mode. Catch PyZoteroError.
reference = self._zotero.get_reference(reference_key)
self.view.model().sourceModel().update_reference(row, reference)
else:
# TODO Display an information dialog.
raise ValueError("No row selected for edition.")
示例2: ListView
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import selectRow [as 别名]
class ListView(QStackedWidget):
PAGE_EMPTY = 0
PAGE_LISTVIEW = 1
def __init__(self, parent = None):
super(ListView, self).__init__(parent=parent)
self.emptyMessage = QLabel("no elements defined yet")
self.emptyMessage.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter )
self.emptyMessage.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.addWidget(self.emptyMessage)
self._table = QTableView()
self.addWidget(self._table)
self._table.clicked.connect(self.tableViewCellClicked)
self._table.doubleClicked.connect(self.tableViewCellDoubleClicked)
self._table.verticalHeader().sectionMoved.connect(self.rowMovedTest)
self._table.setShowGrid(False)
def resetEmptyMessage(self,pystring):
self.emptyMessage.setText(pystring)
def tableViewCellClicked(self, modelIndex):
'''
Reimplemt this function to get interaction when double click
:param modelIndex:
'''
# if (modelIndex.column() == self.model.ColumnID.Delete and
# not self._table.model().flags(modelIndex) == Qt.NoItemFlags):
# self._table.model().removeRow(modelIndex.row())
#
def tableViewCellDoubleClicked(self, modelIndex):
'''
Reimplement this function to get interaction when single click
:param modelIndex:
'''
# if modelIndex.column() == self.model.ColumnID.Color:
# self._colorDialog.setBrushColor(self._table.model()[modelIndex.row()].brushColor())
# self._colorDialog.setPmapColor (self._table.model()[modelIndex.row()].pmapColor())
# self._colorDialog.exec_()
# #print "brush color = {}".format(self._colorDialog.brushColor().name())
# #print "pmap color = {}".format(self._colorDialog.pmapColor().name())
# self._table.model().setData(modelIndex, (self._colorDialog.brushColor(),
# self._colorDialog.pmapColor ()))
def rowMovedTest(self, logicalIndex, oldVisualIndex, newVisualIndex):
logger.debug( "{} {} {}".format(logicalIndex, oldVisualIndex, newVisualIndex) )
def _setListViewLook(self):
table = self._table
#table.setDragEnabled(True)
table.setAcceptDrops(True)
table.setFocusPolicy(Qt.NoFocus)
table.setShowGrid(False)
table.horizontalHeader().hide()
table.verticalHeader().hide()
#table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
table.setSelectionMode(QAbstractItemView.SingleSelection)
table.setSelectionBehavior(QAbstractItemView.SelectRows)
def selectRow(self, *args, **kwargs):
self._table.selectRow(*args, **kwargs)
def _onRowsChanged(self, parent, start, end):
model = self._table.model()
if model and model.rowCount() > 0:
self.setCurrentIndex(self.PAGE_LISTVIEW)
else:
self.setCurrentIndex(self.PAGE_EMPTY)
if self.parent()!=None: self.parent().updateGeometry()
def setModel(self, model):
QTableView.setModel(self._table, model)
self._table.setSelectionModel(model._selectionModel)
if model.rowCount() > 0:
self.setCurrentIndex(self.PAGE_LISTVIEW)
else:
self.setCurrentIndex(self.PAGE_EMPTY)
model.rowsInserted.connect(self._onRowsChanged)
model.rowsRemoved.connect(self._onRowsChanged)
self.model=model
self._setListViewLook()
@property
def allowDelete(self):
return not self._table.isColumnHidden(self.model.ColumnID.Delete)
@allowDelete.setter
def allowDelete(self, allow):
self._table.setColumnHidden(self.model.ColumnID.Delete, not allow)
#.........这里部分代码省略.........
示例3: SubtitleEditor
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import selectRow [as 别名]
#.........这里部分代码省略.........
# create subtitle graphical representation in editor sub list
row = createRow(sub)
self._model.insertRow(subNo, row)
index = self._model.index(subNo, 2)
self._subList.clearSelection()
self._subList.setCurrentIndex(index)
self._subList.edit(index)
def addNewSubtitle(self):
data = self.data
subNo = data.subtitles.size()
indices = self._subList.selectedIndexes()
if len(indices) > 0:
rows = [index.row() for index in indices]
subNo = max(rows) + 1
self._createNewSubtitle(data, subNo)
def insertNewSubtitle(self):
data = self.data
subNo = 0
indices = self._subList.selectedIndexes()
if len(indices) > 0:
rows = [index.row() for index in indices]
subNo = max(rows)
self._createNewSubtitle(data, subNo)
def removeSelectedSubtitles(self):
indices = self._subList.selectedIndexes()
if len(indices) > 0:
rows = list(set([index.row() for index in indices]))
command = RemoveSubtitles(self.filePath, rows)
self._subtitleData.execute(command)
if self._model.rowCount() > rows[-1]:
self._subList.selectRow(rows[-1])
else:
self._subList.selectRow(self._model.rowCount() - 1)
def highlight(self):
self._searchBar.show()
self._searchBar.highlight()
def showContextMenu(self):
self._contextMenu.exec(QCursor.pos())
def changeInputEncoding(self, encoding):
data = self._subtitleData.data(self.filePath)
if encoding != data.inputEncoding:
try:
data.encode(encoding)
except UnicodeDecodeError:
message = QMessageBox(
QMessageBox.Warning,
_("Decoding error"),
_("Cannot decode subtitles to '%s' encoding.\nPlease try different encoding.") % encoding,
QMessageBox.Ok, self
)
message.exec()
except LookupError:
message = QMessageBox(QMessageBox.Warning,
_("Unknown encoding"), _("Unknown encoding: '%s'") % encoding,
QMessageBox.Ok, self
)
message.exec()
else:
# TODO: outputEncoding
command = ChangeData(self.filePath, data, _("Input encoding: %s") % encoding)
示例4: ParamModWgt
# 需要导入模块: from PyQt5.QtWidgets import QTableView [as 别名]
# 或者: from PyQt5.QtWidgets.QTableView import selectRow [as 别名]
class ParamModWgt(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.main_window = parent
self.buildRequiredTagsGB()
# Widgets
self.newParamBtn = QPushButton("New")
self.deleteParamBtn = QPushButton("Delete")
self.paramSaveAnnotBtn = QPushButton("Save")
buttonWidget = QWidget(self)
self.existingParamsGB = QGroupBox("Existing parameters", self)
self.paramListTblWdg = QTableView()
self.paramListModel = ParameterListModel(parent=self)
self.paramListTblWdg.setSelectionBehavior(QAbstractItemView.SelectRows)
self.paramListTblWdg.setSelectionMode(QAbstractItemView.SingleSelection)
self.paramListTblWdg.setModel(self.paramListModel)
self.paramListTblWdg.setColumnWidth(0, 150)
self.paramListTblWdg.setColumnWidth(1, 350)
self.relationWgt = ParamRelationWgt(parent)
self.newParamsGB = QGroupBox("Parameter details", self)
self.resultTypeCbo = QComboBox(self)
self.isExpProp = QCheckBox("is an experimental property", self)
self.resultTypeCbo.addItems(["point value", "function", "numerical trace"])
self.singleValueParamWgt = ParamValueWgt(parent)
self.functionParamWgt = ParamFunctionWgt(parent)
self.traceParamWgt = ParamTraceWgt(parent)
self.functionParamWgt.mainWgt = self
self.paramModStack = QStackedWidget(self)
self.paramModStack.addWidget(self.singleValueParamWgt)
self.paramModStack.addWidget(self.functionParamWgt)
self.paramModStack.addWidget(self.traceParamWgt)
# Signals
selectionModel = self.paramListTblWdg.selectionModel()
selectionModel.selectionChanged.connect(self.selectedParameterChanged)
self.newParamBtn.clicked.connect(self.newParameter)
self.deleteParamBtn.clicked.connect(self.deleteParameter)
self.paramSaveAnnotBtn.clicked.connect(self.saveParameter)
self.resultTypeCbo.currentIndexChanged.connect(self.paramModStack.setCurrentIndex)
self.singleValueParamWgt.paramTypeSelected.connect(self.newParamTypeSelected)
self.functionParamWgt.paramTypeSelected.connect(self.newParamTypeSelected)
self.traceParamWgt.paramTypeSelected.connect(self.newParamTypeSelected)
# Layout
buttonLayout = QVBoxLayout(buttonWidget)
buttonLayout.addWidget(self.paramSaveAnnotBtn)
buttonLayout.addWidget(self.deleteParamBtn)
buttonLayout.addWidget(self.newParamBtn)
existGrid = QHBoxLayout(self.existingParamsGB)
existGrid.addWidget(buttonWidget)
existGrid.addWidget(self.paramListTblWdg)
newGrid = QGridLayout(self.newParamsGB)
newGrid.addWidget(QLabel("Result type"), 0, 0)
newGrid.addWidget(self.resultTypeCbo, 0, 1)
newGrid.addWidget(self.isExpProp, 0, 2)
newGrid.addWidget(self.paramModStack, 1, 0, 1, 3)
newGrid.addWidget(self.relationWgt, 1, 3)
layout = QVBoxLayout(self)
self.rootLayout = QSplitter(Qt.Vertical, self)
self.rootLayout.setOrientation(Qt.Vertical)
self.rootLayout.addWidget(self.existingParamsGB)
self.rootLayout.addWidget(self.newParamsGB)
self.rootLayout.addWidget(self.requireTagGB)
layout.addWidget(self.rootLayout)
# Initial behavior
self.newParamBtn.setEnabled(True)
self.deleteParamBtn.setEnabled(False)
self.paramSaveAnnotBtn.setEnabled(False)
self.additionMode = False
self.newParamsGB.setEnabled(False)
def setRootLayoutSizes(self, sizes):
self.rootLayout.setSizes(sizes)
def viewParameter(self, parameter):
row = -1
for row, param in enumerate(self.paramListModel.parameterList):
if param.id == parameter.id:
break
assert(row > -1)
self.paramListTblWdg.selectRow(row)
#.........这里部分代码省略.........