本文整理汇总了Python中AnyQt.QtWidgets.QLineEdit.cursorPosition方法的典型用法代码示例。如果您正苦于以下问题:Python QLineEdit.cursorPosition方法的具体用法?Python QLineEdit.cursorPosition怎么用?Python QLineEdit.cursorPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.cursorPosition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FeatureEditor
# 需要导入模块: from AnyQt.QtWidgets import QLineEdit [as 别名]
# 或者: from AnyQt.QtWidgets.QLineEdit import cursorPosition [as 别名]
#.........这里部分代码省略.........
["Select Feature"], parent=self)
self.attributescb = QComboBox(
minimumContentsLength=16,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon,
sizePolicy=QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
)
self.attributescb.setModel(self.attrs_model)
sorted_funcs = sorted(self.FUNCTIONS)
self.funcs_model = itemmodels.PyListModelTooltip()
self.funcs_model.setParent(self)
self.funcs_model[:] = chain(["Select Function"], sorted_funcs)
self.funcs_model.tooltips[:] = chain(
[''],
[self.FUNCTIONS[func].__doc__ for func in sorted_funcs])
self.functionscb = QComboBox(
minimumContentsLength=16,
sizeAdjustPolicy=QComboBox.AdjustToMinimumContentsLengthWithIcon,
sizePolicy=QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum))
self.functionscb.setModel(self.funcs_model)
hbox = QHBoxLayout()
hbox.addWidget(self.attributescb)
hbox.addWidget(self.functionscb)
layout.addRow(self.nameedit, self.expressionedit)
layout.addRow(self.tr(""), hbox)
self.setLayout(layout)
self.nameedit.editingFinished.connect(self._invalidate)
self.expressionedit.textChanged.connect(self._invalidate)
self.attributescb.currentIndexChanged.connect(self.on_attrs_changed)
self.functionscb.currentIndexChanged.connect(self.on_funcs_changed)
self._modified = False
def setModified(self, modified):
if not type(modified) is bool:
raise TypeError
if self._modified != modified:
self._modified = modified
self.modifiedChanged.emit(modified)
def modified(self):
return self._modified
modified = Property(bool, modified, setModified,
notify=modifiedChanged)
def setEditorData(self, data, domain):
self.nameedit.setText(data.name)
self.expressionedit.setText(data.expression)
self.setModified(False)
self.featureChanged.emit()
self.attrs_model[:] = ["Select Feature"]
if domain is not None and (domain or domain.metas):
self.attrs_model[:] += chain(domain.attributes,
domain.class_vars,
domain.metas)
def editorData(self):
return FeatureDescriptor(name=self.nameedit.text(),
expression=self.nameedit.text())
def _invalidate(self):
self.setModified(True)
self.featureEdited.emit()
self.featureChanged.emit()
def on_attrs_changed(self):
index = self.attributescb.currentIndex()
if index > 0:
attr = sanitized_name(self.attrs_model[index].name)
self.insert_into_expression(attr)
self.attributescb.setCurrentIndex(0)
def on_funcs_changed(self):
index = self.functionscb.currentIndex()
if index > 0:
func = self.funcs_model[index]
if func in ["atan2", "fmod", "ldexp", "log",
"pow", "copysign", "hypot"]:
self.insert_into_expression(func + "(,)")
self.expressionedit.cursorBackward(False, 2)
elif func in ["e", "pi"]:
self.insert_into_expression(func)
else:
self.insert_into_expression(func + "()")
self.expressionedit.cursorBackward(False)
self.functionscb.setCurrentIndex(0)
def insert_into_expression(self, what):
cp = self.expressionedit.cursorPosition()
ct = self.expressionedit.text()
text = ct[:cp] + what + ct[cp:]
self.expressionedit.setText(text)
self.expressionedit.setFocus()