本文整理汇总了Python中PySide.QtGui.QTableView类的典型用法代码示例。如果您正苦于以下问题:Python QTableView类的具体用法?Python QTableView怎么用?Python QTableView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTableView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSetModel
def testSetModel(self):
model = VirtualList()
model._getItemCalled = False
table = QTableView()
table.setModel(model)
table.show()
self.assertFalse(model._getItemCalled)
示例2: __init__
def __init__(self):
super(PhoneFrame, self).__init__()
self.setWindowTitle('Phone Book.')
self.name = QLineEdit()
self.number = QLineEdit()
entry = QFormLayout()
entry.addRow(QLabel('Name'), self.name)
entry.addRow(QLabel('Number'), self.number)
buttons = QHBoxLayout()
button = QPushButton('&Add')
button.clicked.connect(self._addEntry)
buttons.addWidget(button)
button = QPushButton('&Update')
button.clicked.connect(self._updateEntry)
buttons.addWidget(button)
button = QPushButton('&Delete')
button.clicked.connect(self._deleteEntry)
buttons.addWidget(button)
dataDisplay = QTableView()
dataDisplay.setModel(PhoneDataModel())
layout = QVBoxLayout()
layout.addLayout(entry)
layout.addLayout(buttons)
layout.addWidget(dataDisplay)
self.setLayout(layout)
self.show()
示例3: testReferreedObjectSurvivalAfterContextEnd
def testReferreedObjectSurvivalAfterContextEnd(self):
'''Model object assigned to a view object must survive after getting out of context.'''
def createModelAndSetToView(view):
model = TestModel()
model.setObjectName('created model')
view.setModel(model)
view = QTableView()
createModelAndSetToView(view)
model = view.model()
示例4: testReferenceCountingWhenDeletingReferrer
def testReferenceCountingWhenDeletingReferrer(self):
'''Tests reference count of model object referred by deceased view object.'''
model = TestModel()
refcount1 = getrefcount(model)
view = QTableView()
view.setModel(model)
self.assertEqual(getrefcount(view.model()), refcount1 + 1)
del view
self.assertEqual(getrefcount(model), refcount1)
示例5: MainWindow
class MainWindow(QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.layout = QVBoxLayout(self)
self.grid = QTableView()
self.grid.setModel(TaskTableModel(TaskView()))
self.layout.addWidget(self.grid)
示例6: MainWindow
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()]
示例7: __init__
def __init__(self, parameter, parent=None):
_ParameterWidget.__init__(self, parameter, parent)
# Variables
model = _LayerModel()
self._material_class = Material
# Actions
act_add = QAction(getIcon("list-add"), "Add layer", self)
act_remove = QAction(getIcon("list-remove"), "Remove layer", self)
act_clean = QAction(getIcon('edit-clear'), "Clear", self)
# Widgets
self._cb_unit = UnitComboBox('m')
self._cb_unit.setUnit('um')
self._tbl_layers = QTableView()
self._tbl_layers.setModel(model)
self._tbl_layers.setItemDelegate(_LayerDelegate())
header = self._tbl_layers.horizontalHeader()
header.setResizeMode(QHeaderView.Stretch)
header.setStyleSheet('color: blue')
self._tlb_layers = QToolBar()
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self._tlb_layers.addWidget(spacer)
self._tlb_layers.addAction(act_add)
self._tlb_layers.addAction(act_remove)
self._tlb_layers.addAction(act_clean)
# Layouts
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
sublayout = QHBoxLayout()
sublayout.addStretch()
sublayout.addWidget(QLabel('Thickness unit'))
sublayout.addWidget(self._cb_unit)
layout.addLayout(sublayout)
layout.addWidget(self._tbl_layers)
layout.addWidget(self._tlb_layers)
self.setLayout(layout)
# Signals
self.valuesChanged.connect(self._onChanged)
self.validationRequested.connect(self._onChanged)
act_add.triggered.connect(self._onAdd)
act_remove.triggered.connect(self._onRemove)
act_clean.triggered.connect(self._onClear)
self._tbl_layers.doubleClicked.connect(self._onDoubleClicked)
model.dataChanged.connect(self.valuesChanged)
model.rowsInserted.connect(self.valuesChanged)
model.rowsRemoved.connect(self.valuesChanged)
self.validationRequested.emit()
示例8: test_database_view
def test_database_view(qtbot, session):
session.add(Person(name="Roger Milla"))
session.add(Person(name="François Biyik"))
session.add(Person(name="Salvatore Schillaci"))
session.commit()
persons = DatabaseObjectModel(Person, session)
persons.addAttributeColumn("name", "Name")
assert persons.data(ModelIndexDuck(0, 0), Qt.DisplayRole) == "Roger Milla"
view = QTableView()
view.setModel(persons)
persons.appendObject(Person(name="Claudio Cannigia"))
persons.removeObject(0)
qtbot.addWidget(view)
view.show()
示例9: setupUi
def setupUi(self):
centralWidget = QWidget(self)
centralWidget.setLayout(QVBoxLayout(centralWidget))
self.view = QTableView(centralWidget)
self.view.setSortingEnabled(True)
centralWidget.layout().addWidget(self.view)
self.searchBox = QLineEdit(centralWidget)
centralWidget.layout().addWidget(self.searchBox)
self.setCentralWidget(centralWidget)
self.searchBox.setFocus()
示例10: MainWindow
class MainWindow(QMainWindow):
COLUMNS = ['Name', 'Comment']
ITEMS = [
('Ford', "Don't panic"),
('Marvin', "I'm feeling so depressed")
]
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.setupUi()
# setup a sample model
self.model = QStandardItemModel(self)
self.model.setHorizontalHeaderLabels(self.COLUMNS)
for row, item in enumerate(self.ITEMS):
for column, cell in enumerate(item):
self.model.setItem(row, column, QStandardItem(cell))
self.proxy = QSortFilterProxyModel(self)
self.proxy.setSourceModel(self.model)
# filter all columns (use 0, 1, etc. to only filter by a specific column)
self.proxy.setFilterKeyColumn(-1)
# filter text case insensitively
self.proxy.setFilterCaseSensitivity(Qt.CaseInsensitive)
self.view.setModel(self.proxy)
for column, _ in enumerate(self.COLUMNS):
self.view.resizeColumnToContents(column)
self.searchBox.textChanged.connect(self.updateFilter)
def updateFilter(self, text):
self.proxy.setFilterFixedString(text)
def setupUi(self):
centralWidget = QWidget(self)
centralWidget.setLayout(QVBoxLayout(centralWidget))
self.view = QTableView(centralWidget)
self.view.setSortingEnabled(True)
centralWidget.layout().addWidget(self.view)
self.searchBox = QLineEdit(centralWidget)
centralWidget.layout().addWidget(self.searchBox)
self.setCentralWidget(centralWidget)
self.searchBox.setFocus()
示例11: setup_ui
def setup_ui(self):
splitter = QSplitter(self)
left = QWidget(splitter)
left.setLayout(QVBoxLayout(left))
left.layout().addWidget(QLabel('QTableView', left))
tableview = QTableView(left)
tableview.setModel(TableModel(tableview))
left.layout().addWidget(tableview)
splitter.addWidget(left)
right = QWidget(splitter)
right.setLayout(QVBoxLayout(right))
right.layout().addWidget(QLabel('QTableWidget', right))
# create a table widget for DATA
tablewidget = QTableWidget(len(DATA), len(DATA[1]), right)
right.layout().addWidget(tablewidget)
splitter.addWidget(right)
self.setCentralWidget(splitter)
# add tablewidget data
self.add_data(tablewidget)
示例12: _initUI
def _initUI(self):
# Variables
self._widgets = {}
tbl_model = self._LimitTableModel()
# Widgets
self._cb_limit = QComboBox()
self._cb_limit.setModel(self._LimitComboBoxModel())
btn_limit_add = QPushButton()
btn_limit_add.setIcon(getIcon("list-add"))
self._tbl_limit = QTableView()
self._tbl_limit.setModel(tbl_model)
self._tbl_limit.setItemDelegate(self._LimitTableDelegate())
header = self._tbl_limit.horizontalHeader()
header.setResizeMode(QHeaderView.Stretch)
header.hide()
policy = self._tbl_limit.sizePolicy()
policy.setVerticalStretch(True)
self._tbl_limit.setSizePolicy(policy)
tlb_limit = QToolBar()
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
tlb_limit.addWidget(spacer)
act_remove = tlb_limit.addAction(getIcon("list-remove"), "Remove limit")
act_clear = tlb_limit.addAction(getIcon("edit-clear"), "Clear")
# Layouts
layout = _ExpandableOptionsWizardPage._initUI(self)
sublayout = QHBoxLayout()
sublayout.addWidget(self._cb_limit, 1)
sublayout.addWidget(btn_limit_add)
layout.addRow("Select", sublayout)
layout.addRow(self._tbl_limit)
layout.addRow(tlb_limit)
# Signals
btn_limit_add.released.connect(self._onLimitAdd)
act_remove.triggered.connect(self._onLimitRemove)
act_clear.triggered.connect(self._onLimitClear)
self._tbl_limit.doubleClicked.connect(self._onLimitDoubleClicked)
tbl_model.dataChanged.connect(self.valueChanged)
tbl_model.rowsInserted.connect(self.valueChanged)
tbl_model.rowsRemoved.connect(self.valueChanged)
return layout
示例13: __init__
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
database = QSqlDatabase.addDatabase('QSQLITE')
database.setDatabaseName('astatsscraper.db') # Better lookup logic needed
if not database.open():
print('Error opening database!')
model = QSqlTableModel(db=database)
model.setTable('steam_apps')
table = QTableView()
table.setEditTriggers(QAbstractItemView.NoEditTriggers)
table.setModel(model)
self.setCentralWidget(table)
table.show()
示例14: _initUI
def _initUI(self):
# Widgets
self._tbl_warnings = QTableView()
self._tbl_warnings.setModel(self._WarningTableModel())
header = self._tbl_warnings.horizontalHeader()
header.setResizeMode(1, QHeaderView.Stretch)
policy = self._tbl_warnings.sizePolicy()
policy.setVerticalStretch(True)
self._tbl_warnings.setSizePolicy(policy)
# Layouts
layout = _OptionsWizardPage._initUI(self)
layout.addRow(self._tbl_warnings)
return layout
示例15: _init_gui
def _init_gui(self):
self._widget = QSplitter(self, Qt.Horizontal)
self._hierarchy_view = QTreeView(self._widget)
self._details_view = QTableView(self._widget)
self._widget.addWidget(self._hierarchy_view)
self._widget.addWidget(self._details_view)
self._widget.setStretchFactor(0, 2)
self._widget.setStretchFactor(1, 1)
self.setCentralWidget(self._widget)
self._hierarchy_view.setModel(self._hierarchy_model)
self._details_view.setModel(self._details_model)
self._hierarchy_view.expanded.connect(self._mo_item_expand)