本文整理汇总了Python中PyQt5.QtWidgets.QStyledItemDelegate.createEditor方法的典型用法代码示例。如果您正苦于以下问题:Python QStyledItemDelegate.createEditor方法的具体用法?Python QStyledItemDelegate.createEditor怎么用?Python QStyledItemDelegate.createEditor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QStyledItemDelegate
的用法示例。
在下文中一共展示了QStyledItemDelegate.createEditor方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent, option, index): # residNum,residNum_color, residName, atomName, atomNum, X,Y,Z
if index.column() == residNum:
spinbox = QSpinBox(parent)
spinbox.setRange(1, 200000)
spinbox.setSingleStep(1)
spinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
return spinbox
elif index.column() == residName:
combobox = QComboBox(parent)
combobox.addItems(comboBoxList)
combobox.insertSeparator(23)
combobox.setEditable(True)
return combobox
elif index.column() == atomName:
editor = QLineEdit(parent)
editor.returnPressed.connect(self.commitAndCloseEditor)
return editor
elif index.column() == atomNum:
spinbox = QSpinBox(parent)
spinbox.setRange(1, 200000)
spinbox.setSingleStep(1)
spinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
return spinbox
elif index.column() in (X, Y, Z): ###this works
dspinbox = QDoubleSpinBox(parent)
dspinbox.setRange(-200000, 200000)
dspinbox.setSingleStep(0.1)
dspinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
return dspinbox
else:
return QStyledItemDelegate.createEditor(self, parent, option,
index)
示例2: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent, option, idx):
if idx.column() != 1:
return None
item = self.attrs_widget.model.itemFromIndex(idx)
attr, dv = item.data(Qt.UserRole)
text = item.text()
if attr == ua.AttributeIds.NodeId:
return None
if dv.Value.VariantType == ua.VariantType.Boolean:
combo = QComboBox(parent)
combo.addItem("True")
combo.addItem("False")
combo.setCurrentText(text)
return combo
elif attr == ua.AttributeIds.NodeClass:
combo = QComboBox(parent)
for nclass in ua.NodeClass:
combo.addItem(nclass.name)
combo.setCurrentText(text)
return combo
elif attr == ua.AttributeIds.DataType:
nodeid = getattr(ua.ObjectIds, text)
node = Node(self.attrs_widget.current_node.server, nodeid)
startnode = Node(self.attrs_widget.current_node.server, ua.ObjectIds.BaseDataType)
button = GetNodeButton(parent, node, startnode)
return button
elif attr in (ua.AttributeIds.AccessLevel,
ua.AttributeIds.UserAccessLevel,
ua.AttributeIds.WriteMask,
ua.AttributeIds.UserWriteMask,
ua.AttributeIds.EventNotifier):
#FIXME: make a ByteEditor we can choose and click bit ala QtCreator
raise NotImplementedError
else:
return QStyledItemDelegate.createEditor(self, parent, option, idx)
示例3: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent, option, idx):
"""
Called when editing starts, here can we override default editor,
disable editing for some values, etc...
"""
if idx.column() != 2 or idx.row() == 0:
return None
return QStyledItemDelegate.createEditor(self, parent, option, idx)
示例4: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent, option, idx):
if idx.column() != 1:
return None
item = self.attrs_widget.model.itemFromIndex(idx)
data = item.data(Qt.UserRole)
if not data.is_editable():
return None
text = item.text()
if isinstance(data, (ListData, MemberData)):
return QStyledItemDelegate.createEditor(self, parent, option, idx)
elif data.attr == ua.AttributeIds.NodeId:
return None
elif data.uatype == ua.VariantType.Boolean:
combo = QComboBox(parent)
combo.addItem("True")
combo.addItem("False")
combo.setCurrentText(text)
return combo
elif data.attr == ua.AttributeIds.NodeClass:
combo = QComboBox(parent)
for nclass in ua.NodeClass:
combo.addItem(nclass.name)
combo.setCurrentText(text)
return combo
elif data.attr == ua.AttributeIds.ValueRank:
combo = QComboBox(parent)
for rank in ua.ValueRank:
combo.addItem(rank.name)
combo.setCurrentText(text)
return combo
elif data.attr == ua.AttributeIds.DataType:
#nodeid = getattr(ua.ObjectIds, text)
nodeid = data.value
node = Node(self.attrs_widget.current_node.server, nodeid)
startnode = Node(self.attrs_widget.current_node.server, ua.ObjectIds.BaseDataType)
button = GetNodeButton(parent, node, startnode)
return button
elif data.attr in (ua.AttributeIds.AccessLevel,
ua.AttributeIds.UserAccessLevel,
ua.AttributeIds.WriteMask,
ua.AttributeIds.UserWriteMask,
ua.AttributeIds.EventNotifier):
return BitEditor(parent, data.attr, data.value)
else:
return QStyledItemDelegate.createEditor(self, parent, option, idx)
示例5: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent, option, idx):
#---------------------------------------------------------
#
# Child item
#
if idx.parent().isValid():
if idx.column() == self.Parent.colVALUE:
name = idx.sibling(idx.row(), 0).data()
for i in self.Parent.FieldItemsTable:
if i[0] == name:
if i[2]:
editor = TComboBox(parent)
editor.setEnabled(True)
editor.addItems( i[2] )
else:
editor = QStyledItemDelegate.createEditor(self, parent, option, idx)
return editor
elif idx.column() == self.Parent.colSELOPT:
editor = TComboBox(parent)
editor.setEnabled(True)
editor.setEditable(False)
editor.addItems( self.Parent.sel_options )
return editor
return
#---------------------------------------------------------
#
# Top-level item
#
if idx.column() == 0:
editor = TComboBox(parent)
editor.setEnabled(True)
editor.setEditable(True)
names = list(self.PropsDict.keys())
names.sort()
editor.addItems(names)
return editor
elif idx.column() == 1:
editor = TComboBox(parent)
name = idx.sibling(idx.row(), 0).data()
if not name or not name in self.PropsDict.keys():
editor.setEnabled(False)
editor.setEditable(False)
else:
editor.setEnabled(True)
editor.setEditable(True)
editor.addItems( self.PropsDict[name] )
return editor
else:
editor = TComboBox(parent)
editor.setEnabled(True)
editor.setEditable(False)
editor.addItems( self.Parent.sel_options )
return editor
示例6: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent, option, index):
"""
Create an editor widget. Note that the LayerWidget always uses persistent editors.
"""
layer = index.data()
if isinstance(layer, Layer):
editor = LayerItemWidget(parent=parent)
editor.is_editor = True
# We set a custom objectName for debug and eventcapture testing purposes.
objName = layer.name
editor.setObjectName("LayerItemWidget_{}".format(objName))
editor.setAutoFillBackground(True)
editor.setPalette(option.palette)
editor.setBackgroundRole(QPalette.Highlight)
editor.layer = layer
self._editors[layer] = editor
return editor
else:
QStyledItemDelegate.createEditor(self, parent, option, index)
示例7: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent_widget, style_option_view_item, model_index):
"""
:type parent_widget: QWidget
:type style_option_view_item: QStyleOptionViewItem
:type model_index: QModelIndex
:param parent_widget:
:param style_option_view_item:
:param model_index:
:return:
"""
return QStyledItemDelegate.createEditor(parent_widget, style_option_view_item, model_index)
示例8: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent, option, idx):
if idx.column() == 1:
name = idx.sibling(idx.row(), 0).data()
etype = self.editors[name][0]
if etype == self.TEXT_DELEGATE:
editor = QStyledItemDelegate.createEditor(self, parent, option, idx)
return editor
else:
editor = TComboBox(parent)
editor.setEnabled(True)
editor.setEditable(True)
editor.addItems( self.editors[name][1] )
return editor
示例9: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent, option, index):
if index.column() in DATE_TIME_COLUMN_LIST:
editor = QDateTimeEdit(parent=parent)
#editor.setMinimumDate(datetime.datetime(year=2018, month=1, day=1, hour=0, minute=0))
#editor.setMaximumDate(datetime.datetime(year=2020, month=9, day=1, hour=18, minute=30))
editor.setDisplayFormat(QT_DATE_TIME_FORMAT)
#editor.setCalendarPopup(True)
# setFrame(): tell whether the line edit draws itself with a frame.
# If enabled (the default) the line edit draws itself inside a frame, otherwise the line edit draws itself without any frame.
editor.setFrame(False)
return editor
else:
return QStyledItemDelegate.createEditor(self, parent, option, index)
示例10: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent, option, index):
if index.column() == ATOM:
combobox = QComboBox(parent)
combobox.addItems(["ATOM", "HETATM"])
combobox.setEditable(True)
return combobox
elif index.column() == serial:
spinbox = QSpinBox(parent)
spinbox.setRange(1, 200000)
spinbox.setSingleStep(1)
spinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
return spinbox
elif index.column() == name:
editor = QLineEdit(parent)
editor.returnPressed.connect(self.commitAndCloseEditor)
return editor
elif index.column() == resName:
combobox = QComboBox(parent)
combobox.addItems(comboBoxList)
combobox.insertSeparator(23)
combobox.setEditable(True)
return combobox
# editor = QLineEdit(parent)
# editor.returnPressed.connect(self.commitAndCloseEditor)
# return editor
elif index.column() == ChainID:
editor = QLineEdit(parent)
editor.returnPressed.connect(self.commitAndCloseEditor)
return editor
elif index.column() == resNum:
spinbox = QSpinBox(parent)
spinbox.setRange(1, 200000)
spinbox.setSingleStep(1)
spinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
return spinbox
elif index.column() in (X, Y, Z, occupancy, charge): ###this works
dspinbox = QDoubleSpinBox(parent)
dspinbox.setRange(-200000, 200000)
dspinbox.setSingleStep(0.1)
dspinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
return dspinbox
else:
return QStyledItemDelegate.createEditor(self, parent, option, index)
示例11: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent_qw: QWidget,
option: QStyleOptionViewItem,
model_index: QModelIndex) -> QWidget:
"""
Args:
parent_qw: Description
option: Description
model_index: Description
Returns:
the widget used to edit the item specified by index for editing
"""
column = model_index.column()
treewidgetitem = self.parent().itemFromIndex(model_index)
if column == 0: # Property Name
return None
elif column == 1:
editor = treewidgetitem.configureEditor(parent_qw, option, model_index)
return editor
else:
return QStyledItemDelegate.createEditor(self,
parent_qw,
option, model_index)
示例12: createEditor
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import createEditor [as 别名]
def createEditor(self, parent_qw: QWidget,
option: QStyleOptionViewItem,
model_index: QModelIndex):
column = model_index.column()
if column == NAME_COL: # Model name
item = self.parent().itemFromIndex(model_index)
if item.CAN_NAME_EDIT:
editor = QLineEdit(parent_qw)
editor.setAlignment(Qt.AlignVCenter)
return editor
elif column == 1: # Visibility checkbox
# editor = QCheckBox(parent_qw)
# setAlignment doesn't work https://bugreports.qt-project.org/browse/QTBUG-5368
# return editor
return None
elif column == COLOR_COL: # Color Picker
editor = QColorDialog(parent_qw)
return editor
else:
return QStyledItemDelegate.createEditor(self,
parent_qw,
option,
model_index)