本文整理汇总了Python中PySide.QtGui.QTableView.setSelectionBehavior方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setSelectionBehavior方法的具体用法?Python QTableView.setSelectionBehavior怎么用?Python QTableView.setSelectionBehavior使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTableView
的用法示例。
在下文中一共展示了QTableView.setSelectionBehavior方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setupTabs
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setSelectionBehavior [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: MainWindow
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setSelectionBehavior [as 别名]
class MainWindow(QWidget):
def __init__(self):
QWidget.__init__(self)
self.resize(640, 480)
vbox = QVBoxLayout()
self.setWindowTitle('TableDemo')
self.setLayout(vbox)
self.table = QTableView()
self.table.setAlternatingRowColors(True)
self.table.setSortingEnabled(True)
self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
cards = [Card(u'巫医', u'战吼:恢复2点生命值。', 1, 2, 1),
Card(u'狼骑兵', u'冲锋', 3, 3, 1),
Card(u'石牙野猪', u'冲锋', 1, 1, 1),
Card(u'森金持盾卫士', u'嘲讽', 4, 3, 5),
]
cardModel = CardModel(cards)
sortModel = QSortFilterProxyModel()
sortModel.setSourceModel(cardModel)
self.table.setModel(sortModel)
vbox.addWidget(self.table)
def printItem(self, idx):
print idx.model().persons[idx.row()]
示例3: uiManager
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setSelectionBehavior [as 别名]
class uiManager(QMainWindow):
def __init__(self):
super(uiManager, self).__init__()
self.setMinimumSize(900,500)
self.setWindowTitle("Manage")
self.aFileModel = FileModel() # Add files
self.sFileModel = FileModel() # Queried files
self.eFileModel = FileModel() # Editing files
self.tabWidget = QTabWidget()
self.setCentralWidget(self.tabWidget)
self.defActions()
self.addTab()
self.searchTab()
self.editTab()
self.testtab()
self.statusBar().showMessage("Hi.")
def defActions(self):
self.findAct = QAction("+", self, triggered=self.findFilesDlg)
self.dropAddTabAct = QAction("-", self, shortcut="Delete",
triggered=self.dropAddTabRows)
self.dropEditTabAct = QAction("-", self, shortcut="Delete",
triggered=self.dropEditTabRows)
def dropEditTabRows(self):
self.dropFiles(self.eFileTable, self.eFileModel)
def dropAddTabRows(self):
self.dropFiles(self.aFileTable, self.aFileModel)
def testtab(self):
self.test = QWidget()
self.tabWidget.addTab(self.test, "WORDS")
self.tabWidget.setCornerWidget(self.test)
def addTab(self):
self.aFileTable = QTableView()
self.aFileTable.setModel(self.aFileModel)
self.aFileTable.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setColumnsWidths(self.aFileTable)
self.addWidget = QWidget()
vLayout = QVBoxLayout()
vLayout.addWidget(self.aFileTable)
addBtn = QToolButton()
addBtn.setDefaultAction(self.findAct)
# addBtn.clicked.connect(self.findFilesDlg)
dropBtn = QToolButton()
dropBtn.setDefaultAction(self.dropAddTabAct)
# rmvBtn.clicked.connect(self.rmvFiles)
insBtn = QPushButton("Track")
insBtn.clicked.connect(self.insert)
hLayout = QHBoxLayout()
hLayout.addWidget(addBtn)
hLayout.addWidget(dropBtn)
hLayout.addStretch(1)
hLayout.addWidget(insBtn)
vLayout.addLayout(hLayout)
self.addWidget.setLayout(vLayout)
self.tabWidget.addTab(self.addWidget, u"Add")
def searchTab(self):
# sFileModel + view tab
self.sFileTable = QTableView()
self.sFileTable.setModel(self.sFileModel)
self.sFileTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.sFileTable.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setColumnsWidths(self.sFileTable)
self.searchWidget = QWidget()
# Horizontal layout
# Button, Line Edit, Button
hLayout = QHBoxLayout()
self.searchBox = QLineEdit()
#.........这里部分代码省略.........