本文整理汇总了Python中PySide.QtGui.QTableView.model方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.model方法的具体用法?Python QTableView.model怎么用?Python QTableView.model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTableView
的用法示例。
在下文中一共展示了QTableView.model方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReferenceCounting
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
def testReferenceCounting(self):
'''Tests reference count of model object referred by view objects.'''
model1 = TestModel()
refcount1 = getrefcount(model1)
view1 = QTableView()
view1.setModel(model1)
self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
view2 = QTableView()
view2.setModel(model1)
self.assertEqual(getrefcount(view2.model()), refcount1 + 2)
model2 = TestModel()
view2.setModel(model2)
self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
示例2: testReferreedObjectSurvivalAfterContextEnd
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
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()
示例3: testReferenceCountingWhenDeletingReferrer
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
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)
示例4: skillsWindow
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
class skillsWindow(QDialog):
def __init__(self, dataModel, oberTablo):
QDialog.__init__(self)
self.setWindowTitle('All Skills')
self.setWindowIcon(QIcon('elance.ico'))
self.oberTablo = oberTablo
#create & configure tablewiew
self.table_view = QTableView()
self.table_view.setModel(dataModel)
self.table_view.setSortingEnabled(True)
self.table_view.sortByColumn(1, Qt.DescendingOrder)
self.table_view.resizeColumnsToContents()
self.table_view.resizeRowsToContents()
#http://stackoverflow.com/questions/7189305/set-optimal-size-of-a-dialog-window-containing-a-tablewidget
#http://stackoverflow.com/questions/8766633/how-to-determine-the-correct-size-of-a-qtablewidget
w = 0
w += self.table_view.contentsMargins().left() +\
self.table_view.contentsMargins().right() +\
self.table_view.verticalHeader().width()
w += qApp.style().pixelMetric(QStyle.PM_ScrollBarExtent)
for i in range(len(self.table_view.model().header)):
w += self.table_view.columnWidth(i)
self.table_view.horizontalHeader().setStretchLastSection(True)
self.table_view.setMinimumWidth(w)
# create two buttons
self.findEntries = QPushButton('Find entries')
self.findEntries.clicked.connect(self.ApplyFilterToMainList)
self.cancel = QPushButton('Cancel')
self.cancel.clicked.connect(self.winClose)
self.mainLayout = QGridLayout()
self.mainLayout.addWidget(self.table_view, 0,0,1,3)
self.mainLayout.addWidget(self.findEntries, 1,0)
self.mainLayout.addWidget(self.cancel, 1,2)
self.setLayout(self.mainLayout)
self.show()
def ApplyFilterToMainList(self):
selection = self.table_view.selectionModel().selection()
skills = []
for selRange in selection:
for index in selRange.indexes():
skill = index.model().data(index, Qt.DisplayRole)
skills.append(skill)
self.oberTablo.model().emit(SIGNAL("modelAboutToBeReset()"))
self.oberTablo.model().criteria = {'Skills':skills}
self.oberTablo.model().emit(SIGNAL("modelReset()"))
self.close()
def winClose(self):
self.close()
示例5: LimitWizardPage
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
#.........这里部分代码省略.........
def insert(self, index, limit):
self.insertRows(index)
self.setData(self.createIndex(index, 0), limit)
def remove(self, limit):
index = self._limits.index(limit)
self.removeRows(index)
def modify(self, index, limit):
self.setData(self.createIndex(index, 0), limit)
def clear(self):
self.removeRows(0, self.rowCount())
def limits(self):
limits = set(self._limits)
limits.discard(None)
return limits
def limit(self, index):
return self._limits[index.row()]
class _LimitTableDelegate(QItemDelegate):
def __init__(self, parent=None):
QItemDelegate.__init__(self, parent)
def createEditor(self, parent, option, index):
return None
def setEditorData(self, editor, index):
pass
def setModelData(self, editor, model, index):
return None
def __init__(self, options, parent=None):
_ExpandableOptionsWizardPage.__init__(self, options, parent)
self.setTitle('Limit')
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)
示例6: LayerListWidget
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
class LayerListWidget(_ParameterWidget):
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()
def _onChanged(self):
if self.hasAcceptableInput():
self._tbl_layers.setStyleSheet("background: none")
else:
self._tbl_layers.setStyleSheet("background: pink")
def _onDoubleClicked(self, index):
if index.column() != 0:
return
model = self._tbl_layers.model()
materials = model.materials(index)
if len(materials) == 0:
dialog = get_material_dialog_class(self._material_class)()
elif len(materials) == 1:
dialog = get_material_dialog_class(self._material_class)()
dialog.setValue(materials[0])
else:
dialog = MaterialListDialog()
dialog.setMaterialClass(self._material_class)
dialog.setValues(materials)
dialog.setReadOnly(self.isReadOnly())
if not dialog.exec_():
return
model.setData(index, dialog.values())
def _onAdd(self):
index = self._tbl_layers.selectionModel().currentIndex()
model = self._tbl_layers.model()
model.insertRows(index.row() + 1)
# Show material dialog right away
index = model.createIndex(index.row() + 1, 0)
#.........这里部分代码省略.........
示例7: RunnerDialog
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
#.........这里部分代码省略.........
self.options_error.connect(self._onOptionsError)
self.results_error.connect(self._onResultsError)
# Defaults
settings = get_settings()
section = settings.add_section('gui')
if hasattr(section, 'outputdir'):
self._txt_outputdir.setPath(section.outputdir)
if hasattr(section, 'maxworkers'):
self._spn_workers.setValue(int(section.maxworkers))
if hasattr(section, 'overwrite'):
state = True if section.overwrite.lower() == 'true' else False
self._chk_overwrite.setChecked(state)
def _onDialogProgressProgress(self, progress, status):
self._dlg_progress.setValue(progress * 100)
self._dlg_progress.setLabelText(status)
def _onDialogProgressCancel(self):
self._dlg_progress.hide()
if self._options_reader_thread is None:
return
self._options_reader_thread.cancel()
self._options_reader_thread.quit()
self._options_reader_thread.wait()
def _onDialogProgressException(self, ex):
self._dlg_progress.hide()
self._options_reader_thread.quit()
self._options_reader_thread.wait()
messagebox.exception(self, ex)
def _onRunningTimer(self):
self._tbl_options.model().reset()
def _onOpen(self):
settings = get_settings()
curdir = getattr(settings.gui, 'opendir', os.getcwd())
filepath, namefilter = \
QFileDialog.getOpenFileName(self, "Open", curdir,
'Options [*.xml] (*.xml)')
if not filepath or not namefilter:
return
settings.gui.opendir = os.path.dirname(filepath)
if not filepath.endswith('.xml'):
filepath += '.xml'
self._options_reader_thread = _OptionsReaderWrapperThread(filepath)
self._dlg_progress.canceled.connect(self._onDialogProgressCancel)
self._options_reader_thread.resultReady.connect(self._onOpened)
self._options_reader_thread.progressUpdated.connect(self._onDialogProgressProgress)
self._options_reader_thread.exceptionRaised.connect(self._onDialogProgressException)
self._options_reader_thread.start()
self._dlg_progress.reset()
self._dlg_progress.show()
def _onOpened(self, options):
self._dlg_progress.hide()
self._options_reader_thread.quit()
self._options_reader_thread.wait()
self._options_reader_thread = None
示例8: PhotonIntensityResultWidget
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
class PhotonIntensityResultWidget(_SaveableResultWidget):
def _initUI(self):
# Variables
model = _PhotonIntensityResultTableModel(self.result())
# Widgets
self._table = QTableView()
self._table.setModel(model)
header = self._table.horizontalHeader()
for i in range(1, 9):
header.setResizeMode(i, QHeaderView.Stretch)
# Layouts
layout = _SaveableResultWidget._initUI(self)
layout.addWidget(self._table)
return layout
def _initToolbox(self):
toolbox = _SaveableResultWidget._initToolbox(self)
self._itm_abbrev = _PhotonIntensityResultAbbreviationToolItem(self)
toolbox.addItem(self._itm_abbrev, "Abbreviations")
itm_detector = DetectorToolItem(self)
toolbox.addItem(itm_detector, "Detector")
self._itm_options = _PhotonIntensityResultOptionsToolItem(self)
self._itm_options.stateChanged.connect(self._onOptionsChanged)
toolbox.addItem(self._itm_options, "Options")
return toolbox
def _onOptionsChanged(self):
model = self._table.model()
model.setShowUncertainty(self._itm_options.showUncertainty())
pg, cg, bg, tg = self._itm_options.showGenerated()
pe, ce, be, te = self._itm_options.showEmitted()
self._table.setColumnHidden(1, not pg)
self._table.setColumnHidden(2, not pe)
self._table.setColumnHidden(3, not cg)
self._table.setColumnHidden(4, not ce)
self._table.setColumnHidden(5, not bg)
self._table.setColumnHidden(6, not be)
self._table.setColumnHidden(7, not tg)
self._table.setColumnHidden(8, not te)
factor = self._itm_options.factor()
model.setFactor(factor)
def dump(self):
rows = []
rows.append(
[
"Transition",
"PG",
"PG unc",
"PE",
"PE unc",
"CG",
"CG unc",
"CE",
"CE unc",
"BG",
"BG unc",
"BE",
"BE unc",
"TG",
"TG unc",
"TE",
"TE unc",
]
)
result = self.result()
for transition in result:
row = [transition]
row.extend(result.intensity(transition, False, False))
row.extend(result.intensity(transition, True, False))
row.extend(result.characteristic_fluorescence(transition, False))
row.extend(result.characteristic_fluorescence(transition, True))
row.extend(result.bremsstrahlung_fluorescence(transition, False))
row.extend(result.bremsstrahlung_fluorescence(transition, True))
row.extend(result.intensity(transition, False, True))
row.extend(result.intensity(transition, True, True))
rows.append(row)
return rows
示例9: ModelTableWidget
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
class ModelTableWidget(QWidget):
dataChanged = Signal(QModelIndex, QModelIndex)
class _ModelTableModel(QAbstractTableModel):
def __init__(self):
QAbstractTableModel.__init__(self)
self._models = []
def rowCount(self, *args, **kwargs):
return len(self._models)
def columnCount(self, *args, **kwargs):
return 2
def data(self, index, role=Qt.DisplayRole):
if not index.isValid() or not (0 <= index.row() < len(self._models)):
return None
if role == Qt.TextAlignmentRole:
return Qt.AlignCenter
model = self._models[index.row()]
if model is None:
return ""
if role == Qt.DisplayRole or role == Qt.ToolTipRole:
column = index.column()
if column == 0:
return str(model.type)
elif column == 1:
return str(model)
return None
def headerData(self, section, orientation, role):
if role != Qt.DisplayRole:
return None
if orientation == Qt.Horizontal:
if section == 0:
return "Type"
elif section == 1:
return "Model"
elif orientation == Qt.Vertical:
return str(section + 1)
def flags(self, index):
if not index.isValid():
return Qt.ItemIsEnabled
return Qt.ItemFlags(QAbstractTableModel.flags(self, index))
def setData(self, index, value, role=Qt.EditRole):
if not index.isValid() or not (0 <= index.row() < len(self._models)):
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)
#.........这里部分代码省略.........
示例10: testModelWithParent
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
def testModelWithParent(self):
view = QTableView()
model = TestModel(None)
view.setModel(model)
samemodel = view.model()
self.assertEqual(model, samemodel)
示例11: DetectorWizardPage
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
#.........这里部分代码省略.........
def clear(self):
self.removeRows(0, self.rowCount())
def detectors(self):
detectors = {}
for key, detector in self._detectors:
if detector is not None:
detectors.setdefault(key, []).append(detector)
return detectors
def detector(self, index):
return self._detectors[index.row()][1]
def key(self, index):
return self._detectors[index.row()][0]
class _DetectorTableDelegate(QItemDelegate):
def __init__(self, parent=None):
QItemDelegate.__init__(self, parent)
def createEditor(self, parent, option, index):
column = index.column()
if column == 0:
editor = QLineEdit(parent)
editor.setValidator(QRegExpValidator(QRegExp(r"^(?!\s*$).+")))
return editor
elif column == 1:
return None
def setEditorData(self, editor, index):
column = index.column()
if column == 0:
key = index.model().data(index, Qt.DisplayRole)
editor.setText(key)
def setModelData(self, editor, model, index):
column = index.column()
if column == 0:
if not editor.hasAcceptableInput():
return
model.setData(index, editor.text())
def __init__(self, options, parent=None):
_ExpandableOptionsWizardPage.__init__(self, options, parent)
self.setTitle('Detector')
def _initUI(self):
# Variables
self._widgets = {}
tbl_model = self._DetectorTableModel()
# Widgets
self._cb_detector = QComboBox()
self._cb_detector.setModel(self._DetectorComboBoxModel())
btn_detector_add = QPushButton()
btn_detector_add.setIcon(getIcon("list-add"))
self._tbl_detector = QTableView()
self._tbl_detector.setModel(tbl_model)
self._tbl_detector.setItemDelegate(self._DetectorTableDelegate())
header = self._tbl_detector.horizontalHeader()
header.setResizeMode(1, QHeaderView.Stretch)
policy = self._tbl_detector.sizePolicy()
policy.setVerticalStretch(True)
示例12: MainWindow
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import model [as 别名]
class MainWindow(QMainWindow):
def __init__(self, datta):
QMainWindow.__init__(self)
self.setWindowTitle('Project Parser')
appIcon = QIcon('search.png')
self.setWindowIcon(appIcon)
self.viewPortBL = QDesktopWidget().availableGeometry().topLeft()
self.viewPortTR = QDesktopWidget().availableGeometry().bottomRight()
self.margin = int(QDesktopWidget().availableGeometry().width()*0.1/2)
self.shirina = QDesktopWidget().availableGeometry().width() - self.margin*2
self.visota = QDesktopWidget().availableGeometry().height() - self.margin*2
self.setGeometry(self.viewPortBL.x() + self.margin, self.viewPortBL.y() + self.margin,
self.shirina, self.visota)
# statusbar
self.myStatusBar = QStatusBar()
self.setStatusBar(self.myStatusBar)
#lower long layout
self.lowerLong = QFrame()
self.detailsLabel = QLabel()
self.skillsLabel = QLabel()
self.urlLabel = QLabel()
self.locationLabel = QLabel()
self.skillsLabel.setText('skills')
self.detailsLabel.setWordWrap(True)
self.la = QVBoxLayout()
self.la.addWidget(self.detailsLabel)
self.la.addWidget(self.skillsLabel)
self.la.addWidget(self.urlLabel)
self.la.addWidget(self.locationLabel)
self.lowerLong.setLayout(self.la)
# table
self.source_model = MyTableModel(self, datta, ['Id', 'Date', 'Title'])
self.proxy_model = myTableProxy(self)
self.proxy_model.setSourceModel(self.source_model)
self.proxy_model.setDynamicSortFilter(True)
self.table_view = QTableView()
self.table_view.setModel(self.proxy_model)
self.table_view.setAlternatingRowColors(True)
self.table_view.resizeColumnsToContents()
self.table_view.resizeRowsToContents()
self.table_view.horizontalHeader().setStretchLastSection(True)
self.table_view.setSortingEnabled(True)
self.table_view.sortByColumn(2, Qt.AscendingOrder)
# events
self.selection = self.table_view.selectionModel()
self.selection.selectionChanged.connect(self.handleSelectionChanged)
#DO NOT use CreateIndex() method, use index()
index = self.proxy_model.index(0,0)
self.selection.select(index, QItemSelectionModel.Select)
self.upperLong = self.table_view
# right side widgets
self.right = QFrame()
self.la1 = QVBoxLayout()
self.btnDownload = QPushButton('Download data')
self.btnDownload.clicked.connect(self.download)
self.myButton = QPushButton('Show Skillls')
self.myButton.clicked.connect(self.showAllSkills)
self.btnSearchByWord = QPushButton('Search by word(s)')
self.btnSearchByWord.clicked.connect(self.onSearchByWord)
self.btnResetFilter= QPushButton('Discard Filter')
self.btnResetFilter.clicked.connect(self.discardFilter)
self.btnCopyURL = QPushButton('URL to Clipboard')
self.btnCopyURL.clicked.connect(self.copyToClipboard)
self.btnExit = QPushButton('Exit')
self.btnExit.clicked.connect(lambda: sys.exit())
self.dateTimeStamp = QLabel()
self.la1.addWidget(self.btnDownload)
self.la1.addSpacing(10)
self.la1.addWidget(self.myButton)
self.la1.addSpacing(10)
self.la1.addWidget(self.btnSearchByWord)
self.la1.addSpacing(10)
self.la1.addWidget(self.btnResetFilter)
self.la1.addSpacing(10)
self.la1.addWidget(self.btnCopyURL)
self.la1.addSpacing(70)
self.la1.addWidget(self.btnExit)
self.la1.addStretch(stretch=0)
self.la1.addWidget(self.dateTimeStamp)
self.right.setLayout(self.la1)
self.right.setFrameShape(QFrame.StyledPanel)
# splitters
self.horiSplit = QSplitter(Qt.Vertical)
self.horiSplit.addWidget(self.upperLong)
self.horiSplit.addWidget(self.lowerLong)
self.horiSplit.setSizes([self.visota/2, self.visota/2])
self.vertiSplit = QSplitter(Qt.Horizontal)
self.vertiSplit.addWidget(self.horiSplit)
self.vertiSplit.addWidget(self.right)
self.vertiSplit.setSizes([self.shirina*3/4, self.shirina*1/4])
self.setCentralWidget(self.vertiSplit)
self.settings = QSettings('elance.ini', QSettings.IniFormat)
self.settings.beginGroup('DATE_STAMP')
#.........这里部分代码省略.........