本文整理汇总了Python中PyQt5.QtCore.QModelIndex.parent方法的典型用法代码示例。如果您正苦于以下问题:Python QModelIndex.parent方法的具体用法?Python QModelIndex.parent怎么用?Python QModelIndex.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QModelIndex
的用法示例。
在下文中一共展示了QModelIndex.parent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __newFolder
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import parent [as 别名]
def __newFolder(self):
"""
Private slot to add a new bookmarks folder.
"""
from .BookmarkNode import BookmarkNode
currentIndex = self.bookmarksTree.currentIndex()
idx = QModelIndex(currentIndex)
sourceIndex = self.__proxyModel.mapToSource(idx)
sourceNode = self.__bookmarksModel.node(sourceIndex)
row = -1 # append new folder as the last item per default
if sourceNode is not None and \
sourceNode.type() != BookmarkNode.Folder:
# If the selected item is not a folder, add a new folder to the
# parent folder, but directly below the selected item.
idx = idx.parent()
row = currentIndex.row() + 1
if not idx.isValid():
# Select bookmarks menu as default.
idx = self.__proxyModel.index(1, 0)
idx = self.__proxyModel.mapToSource(idx)
parent = self.__bookmarksModel.node(idx)
node = BookmarkNode(BookmarkNode.Folder)
node.title = self.tr("New Folder")
self.__bookmarksManager.addBookmark(parent, node, row)
示例2: editorWidget
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import parent [as 别名]
class editorWidget(QWidget, Ui_editorWidget_ui):
"""
`editorWidget` is a class responsible for displaying and editing one
`outlineItem`. This item can be a folder or a text.
It has four views (see `self.setView`)
- For folders: "text", "outline" or "cork" (set in `self.folderView`)
Text: displays a list of `textEditView` in a scroll area
Outline: displays an outline, using an `outlineView`
Cork: displays flash cards, using a `corkView`
- For text: item is simply displayed in a `textEditView`
All those views are contained in `editorWidget` single widget: `self.stack`.
`editorWidget` are managed in `tabSplitted` (that allow to open several
`outlineItem`s, either in Tabs or in split views.
`tabSplitted` are in turn managed by the `mainEditor`, which is unique and
gives UI buttons to manage all those views.
"""
toggledSpellcheck = pyqtSignal(bool)
dictChanged = pyqtSignal(str)
_maxTabTitleLength = 24
def __init__(self, parent):
QWidget.__init__(self, parent)
self.setupUi(self)
self.currentIndex = QModelIndex()
self.currentID = None
self.txtEdits = []
self.scroll.setBackgroundRole(QPalette.Base)
self.toggledSpellcheck.connect(self.txtRedacText.toggleSpellcheck, AUC)
self.dictChanged.connect(self.txtRedacText.setDict, AUC)
self.txtRedacText.setHighlighting(True)
self.currentDict = ""
self.spellcheck = settings.spellcheck
self.folderView = "cork"
self.mw = mainWindow()
self._tabWidget = None # set by mainEditor on creation
self._model = None
# Capture textEdit scrollbar, so that we can put it outside the margins.
self.txtEditScrollBar = self.txtRedacText.verticalScrollBar()
self.txtEditScrollBar.setParent(self)
self.stack.currentChanged.connect(self.setScrollBarVisibility)
# def setModel(self, model):
# self._model = model
# self.setView()
def resizeEvent(self, event):
"""
textEdit's scrollBar has been reparented to self. So we need to
update it's geomtry when self is resized, and put it where we want it
to be.
"""
# Update scrollbar geometry
r = self.geometry()
w = 10 # Cf. style.mainEditorTabSS
r.setWidth(w)
r.moveRight(self.geometry().width())
self.txtEditScrollBar.setGeometry(r)
QWidget.resizeEvent(self, event)
def setScrollBarVisibility(self):
"""
Since the texteEdit scrollBar has been reparented to self, it is not
hidden when stack changes. We have to do it manually.
"""
self.txtEditScrollBar.setVisible(self.stack.currentIndex() == 0)
def setFolderView(self, v):
oldV = self.folderView
if v == "cork":
self.folderView = "cork"
elif v == "outline":
self.folderView = "outline"
else:
self.folderView = "text"
# Saving value
settings.folderView = self.folderView
if oldV != self.folderView and self.currentIndex:
self.setCurrentModelIndex(self.currentIndex)
def setCorkSizeFactor(self, v):
self.corkView.itemDelegate().setCorkSizeFactor(v)
self.redrawCorkItems()
def redrawCorkItems(self):
#.........这里部分代码省略.........
示例3: textEditView
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import parent [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
#.........这里部分代码省略.........
示例4: editorWidget
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import parent [as 别名]
class editorWidget(QWidget, Ui_editorWidget_ui):
toggledSpellcheck = pyqtSignal(bool)
dictChanged = pyqtSignal(str)
def __init__(self, parent):
QWidget.__init__(self, parent)
self.setupUi(self)
self.currentIndex = QModelIndex()
self.currentID = None
self.txtEdits = []
self.scroll.setBackgroundRole(QPalette.Base)
self.toggledSpellcheck.connect(self.txtRedacText.toggleSpellcheck, AUC)
self.dictChanged.connect(self.txtRedacText.setDict, AUC)
self.txtRedacText.setHighlighting(True)
self.currentDict = ""
self.spellcheck = True
self.folderView = "cork"
self.mw = mainWindow()
# def setModel(self, model):
# self._model = model
# self.setView()
def setFolderView(self, v):
oldV = self.folderView
if v == "cork":
self.folderView = "cork"
elif v == "outline":
self.folderView = "outline"
else:
self.folderView = "text"
# Saving value
settings.folderView = self.folderView
if oldV != self.folderView and self.currentIndex:
self.setCurrentModelIndex(self.currentIndex)
def setCorkSizeFactor(self, v):
self.corkView.itemDelegate().setCorkSizeFactor(v)
self.redrawCorkItems()
def redrawCorkItems(self):
r = self.corkView.rootIndex()
if r.isValid():
count = r.internalPointer().childCount()
else:
count = self.mw.mdlOutline.rootItem.childCount()
for c in range(count):
self.corkView.itemDelegate().sizeHintChanged.emit(r.child(c, 0))
def setView(self):
# index = mainWindow().treeRedacOutline.currentIndex()
# Couting the number of other selected items
# sel = []
# for i in mainWindow().treeRedacOutline.selectionModel().selection().indexes():
# if i.column() != 0: continue
# if i not in sel: sel.append(i)
# if len(sel) != 0:
# item = index.internalPointer()
# else:
# index = QModelIndex()
# item = self.mw.mdlOutline.rootItem
# self.currentIndex = index
if self.currentIndex.isValid():
item = self.currentIndex.internalPointer()
else:
item = self.mw.mdlOutline.rootItem
def addTitle(itm):
edt = textEditView(self, html="<h{l}>{t}</h{l}>".format(l=min(itm.level() + 1, 5), t=itm.title()),
autoResize=True)
edt.setFrameShape(QFrame.NoFrame)
self.txtEdits.append(edt)
l.addWidget(edt)
def addLine():
line = QFrame(self.text)
line.setFrameShape(QFrame.HLine)
line.setFrameShadow(QFrame.Sunken)
l.addWidget(line)
def addText(itm):
edt = textEditView(self,
index=itm.index(),
spellcheck=self.spellcheck,
dict=settings.dict,
highlighting=True,
autoResize=True)
edt.setFrameShape(QFrame.NoFrame)
edt.setStyleSheet("background: {};".format(settings.textEditor["background"]))
edt.setStatusTip("{} ({})".format(itm.path(), itm.type()))
self.toggledSpellcheck.connect(edt.toggleSpellcheck, AUC)
self.dictChanged.connect(edt.setDict, AUC)
#.........这里部分代码省略.........
示例5: TreeModel
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import parent [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: textEditView
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import parent [as 别名]
class textEditView(QTextEdit):
def __init__(self, parent=None, index=None, html=None, spellcheck=True, highlighting=False, dict="",
autoResize=False):
QTextEdit.__init__(self, parent)
self._column = Outline.text.value
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.spellcheck = spellcheck
self.currentDict = dict if dict else settings.dict
self.highlighter = None
self.setAutoResize(autoResize)
self._defaultBlockFormat = QTextBlockFormat()
self._defaultCharFormat = QTextCharFormat()
self.highlightWord = ""
self.highligtCS = False
self.defaultFontPointSize = qApp.font().pointSize()
self._dict = None
# self.document().contentsChanged.connect(self.submit, 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, 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 enchant.get_default_language())
except enchant.errors.DictNotFoundError:
self.spellcheck = False
else:
self.spellcheck = False
if self._highlighting and not self.highlighter:
self.highlighter = basicHighlighter(self)
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
def setModel(self, model):
self._model = model
try:
self._model.dataChanged.connect(self.update, AUC)
except TypeError:
pass
try:
self._model.rowsAboutToBeRemoved.connect(self.rowsAboutToBeRemoved, 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
if index.isValid():
self.setEnabled(True)
if index.column() != self._column:
index = index.sibling(index.row(), self._column)
self._index = index
self.setPlaceholderText(self._placeholderText)
if not self._model:
self.setModel(index.model())
#.........这里部分代码省略.........
示例7: expand_item
# 需要导入模块: from PyQt5.QtCore import QModelIndex [as 别名]
# 或者: from PyQt5.QtCore.QModelIndex import parent [as 别名]
def expand_item(self, index: QModelIndex) -> None:
index = self.model().index(index.row(), 0, index.parent())
item = self.model().itemFromIndex(index)
self.load_children(item)