本文整理汇总了Python中PyQt5.QtCore.QModelIndex.data方法的典型用法代码示例。如果您正苦于以下问题:Python QModelIndex.data方法的具体用法?Python QModelIndex.data怎么用?Python QModelIndex.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QModelIndex
的用法示例。
在下文中一共展示了QModelIndex.data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import data [as 别名]
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex):
item_type = index.data(Qt.AccessibleDescriptionRole)
if item_type == "parent":
parent_option = option
parent_option.state |= QStyle.State_Enabled
super().paint(painter, parent_option, index)
elif item_type == "child":
child_option = option
indent = option.fontMetrics.width(4 * " ")
child_option.rect.adjust(indent, 0, 0, 0)
child_option.textElideMode = Qt.ElideNone
super().paint(painter, child_option, index)
else:
super().paint(painter, option, index)
示例2: selection_changed
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import data [as 别名]
def selection_changed(self, curr_index: QModelIndex, prev_index: QModelIndex):
"""
Updates the information about currently selected account.
"""
if not curr_index.isValid():
return None
# Make sure selection is visible in the view
self.selection.setCurrentIndex(
curr_index, QItemSelectionModel.SelectCurrent)
acc = curr_index.data(role=Qt.UserRole)
# Set the type of account
self.typeBox.setCurrentText(acc.type)
# Set the checkboxes
self.closedBox.setChecked(acc.closed)
self.exBudgetBox.setChecked(acc.exbudget)
示例3: account_clicked
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import data [as 别名]
def account_clicked(self, index: QModelIndex):
"""
Opens the list of transactions for given index in the account
tree model.
"""
account = index.data(role=Qt.UserRole)
if not isinstance(account, Account):
return
transaction_manager = TransactionsRoll(self.orm, account)
self.menuBar.setEnabled(False)
transaction_manager.exec()
self.menuBar.setEnabled(True)
# Update if there was changes
self.show_accounts()
self.show_budget_report()
示例4: textEditView
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import data [as 别名]
class textEditView(QTextEdit):
def __init__(self, parent=None, index=None, html=None, spellcheck=None,
highlighting=False, dict="", autoResize=False):
QTextEdit.__init__(self, parent)
self._column = Outline.text
self._index = None
self._indexes = None
self._model = None
self._placeholderText = self.placeholderText()
self._updating = False
self._item = None
self._highlighting = highlighting
self._textFormat = "text"
self.setAcceptRichText(False)
# When setting up a theme, this becomes true.
self._fromTheme = False
self._themeData = None
self._highlighterClass = BasicHighlighter
if spellcheck is None:
spellcheck = settings.spellcheck
self.spellcheck = spellcheck
self.currentDict = dict if dict else settings.dict
self._defaultFontSize = qApp.font().pointSize()
self.highlighter = None
self.setAutoResize(autoResize)
self._defaultBlockFormat = QTextBlockFormat()
self._defaultCharFormat = QTextCharFormat()
self.highlightWord = ""
self.highligtCS = False
self._dict = None
# self.document().contentsChanged.connect(self.submit, F.AUC)
# Submit text changed only after 500ms without modifications
self.updateTimer = QTimer()
self.updateTimer.setInterval(500)
self.updateTimer.setSingleShot(True)
self.updateTimer.timeout.connect(self.submit)
# self.updateTimer.timeout.connect(lambda: print("Timeout"))
self.updateTimer.stop()
self.document().contentsChanged.connect(self.updateTimer.start, F.AUC)
# self.document().contentsChanged.connect(lambda: print("Document changed"))
# self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed"))
self.setEnabled(False)
if index:
self.setCurrentModelIndex(index)
elif html:
self.document().setHtml(html)
self.setReadOnly(True)
# Spellchecking
if enchant and self.spellcheck:
try:
self._dict = enchant.Dict(self.currentDict if self.currentDict
else self.getDefaultLocale())
except enchant.errors.DictNotFoundError:
self.spellcheck = False
else:
self.spellcheck = False
if self._highlighting and not self.highlighter:
self.highlighter = self._highlighterClass(self)
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
def getDefaultLocale(self):
default_locale = enchant.get_default_language()
if default_locale is None:
default_locale = QLocale.system().name()
if default_locale is None:
default_locale = enchant.list_dicts()[0][0]
return default_locale
def setModel(self, model):
self._model = model
try:
self._model.dataChanged.connect(self.update, F.AUC)
except TypeError:
pass
def setColumn(self, col):
self._column = col
def setHighlighting(self, val):
self._highlighting = val
def setDefaultBlockFormat(self, bf):
self._defaultBlockFormat = bf
if self.highlighter:
self.highlighter.setDefaultBlockFormat(bf)
def setCurrentModelIndex(self, index):
self._indexes = None
#.........这里部分代码省略.........
示例5: TreeModel
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import data [as 别名]
class TreeModel(QAbstractItemModel):
# Funktion hasChildren?
# signals
statusChanged = pyqtSignal(QModelIndex)
speciesChanged = pyqtSignal(QModelIndex, int, int)
calculated = pyqtSignal()
itemsInserted = pyqtSignal(bool)
itemsAboutToBeCalculated = pyqtSignal(bool)
allItemsRemoved = pyqtSignal(bool)
# class constants
ItemRole = Qt.UserRole + 1
StatusRole = Qt.UserRole + 2
ColorRole = Qt.UserRole + 3
TypeRole = Qt.UserRole + 4
NameRole = Qt.UserRole + 5
ResultRole = Qt.UserRole + 6
PlantRole = Qt.UserRole + 7
ProtectionRole = Qt.UserRole + 8
SpeciesRole = Qt.UserRole + 9
TypeRole = Qt.UserRole + 10
IdentificationRole = Qt.UserRole + 11
LengthRole = Qt.UserRole + 12
CountRole = Qt.UserRole + 13
_roles = {ItemRole : "item",
StatusRole : "status",
ColorRole : "color",
TypeRole : "type",
NameRole : "name",
ResultRole : "result",
PlantRole : "plant",
ProtectionRole : "protection",
IdentificationRole : "identification",
LengthRole : "length",
CountRole : "count"}
TYPE, IDENTIFICATION, SPECIES, NAME = range(4)
def __init__(self, parent=None):
super().__init__(parent)
self.root = VariantItem("root item")
# species registry
self.species = {}
self.variants = 0
# initialize class attributes
self._TABLE_HEADER_LABELS = (QtCore.QT_TRANSLATE_NOOP("TreeModel", "Protection type"),
QtCore.QT_TRANSLATE_NOOP("TreeModel", "Name"),
QtCore.QT_TRANSLATE_NOOP("TreeModel", "Tree species"),
QtCore.QT_TRANSLATE_NOOP("TreeModel", "Description of protection"))
# project settings
self.project = Project()
self.rowsInserted.connect(self.updateSpecies)
self.speciesChanged.connect(self.moveItem)
self.statusChanged.connect(self.updateStatus)
self.new = True
self.changed = False
self.filename = ""
self.file = False
self.read = False
self.last = QModelIndex()
self.current = -1
self.count = 0 # temoporary plant count for calculation help
self.length = 0 # temoporary fence length for calculation help
def columnCount(self, parent):
return len(self._TABLE_HEADER_LABELS)
def roleNames(self):
return self._roles
def projectData(self, key):
return getattr(self.project, key)
def setProjectData(self, key, value):
setattr(self.project, key, value)
self.changed = True
def itemData(self, index):
if not index.isValid():
return None
item = self.getItem(index)
# create the QMap as python dict
data = {
self.NameRole : item.name,
self.ColorRole : item.color,
self.StatusRole : item.status,
self.PlantRole : item.plant,
self.ProtectionRole : item.protection
}
#.........这里部分代码省略.........
示例6: on_projectTree_doubleClicked
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import data [as 别名]
def on_projectTree_doubleClicked(self, idx: QModelIndex):
p = idx.data(Qt.UserRole).page
if p is not None:
self.openPage.emit(p)