我在我的项目中实现了这个类:
class ScriptEditorTextBox(QsciScintilla):
def __init__(self, parent):
QsciScintilla.__init__(self)
#Lexer
lexer = QsciLexerPython()
#AutoCompletion
api = Qsci.QsciAPIs(lexer)
api.add('aLongString')
api.add('aLongerString')
api.add('aDifferentString')
api.add('sOmethingElse')
api.prepare()
self.setLexer(lexer)
self.setAutoCompletionThreshold(1)
self.setAutoCompletionSource(QsciScintilla.AcsAPIs)
#LineHighlight
self.setCaretLineVisible(True)
self.setCaretLineBackgroundColor(QColor("gainsboro"))
#AutoIndentation
self.setAutoIndent(True)
self.setIndentationGuides(True)
self.setIndentationsUseTabs(True)
self.setIndentationWidth(4)
#Margins
self.setMarginsBackgroundColor(QColor("gainsboro"))
self.setMarginsFont(QFont("Consolas", 9, 87))
self.setMarginLineNumbers(1, True)
self.setMarginLineNumbers(2, False)
self.setMarginWidth(1, QString().setNum(10))
self.setMarginWidth(2, 10)
self.connect(self, SIGNAL("linesChanged()"), self._linesChanged)
def _linesChanged(self):
width = QString().setNum(self.lines() * 10)
self.setMarginWidth(1, width)一切开始都很好,但是当我按enter键之后:它就不会自动缩进。而且,也没有自动补全(但我甚至不知道应该自动补全什么)。
如果有任何建议,我将不胜感激。
发布于 2015-02-28 05:47:31
这两个问题都是由于未能正确引用词法分析器而导致的。
如果执行以下操作,示例代码将正常工作:
lexer = QsciLexerPython(self)或者这样:
self.lexer = QsciLexerPython()
...
api = Qsci.QsciAPIs(self.lexer)
...
self.setLexer(self.lexer)https://stackoverflow.com/questions/28765761
复制相似问题