문제
PYQT4의 텍스트 편집기에 구문 강조 표시를 추가하려고합니다. 문서에서 C ++에서 컴파일 된 시점을 찾는 작품을 찾았지만 Python/Pyqt로 변환하면 더 이상 작동하지 않습니다.
실패하는 코드의 일부 (더 이상 아무것도 강조하지 않음)는 다음과 같습니다.
def highlightCurrentLine(self):
extraSelections = []
if not self.isReadOnly():
selection = QTextEdit.ExtraSelection()
lineColor = QColor(Qt.yellow).lighter(160)
selection.format.setBackground(lineColor)
selection.format.setProperty(QTextFormat.FullWidthSelection, QVariant(True))
selection.cursor = self.textCursor()
selection.cursor.clearSelection()
extraSelections.append(selection)
self.setExtraSelections(extraSelections)
다음은 다음과 같이 호출됩니다.
self.connect(self, SIGNAL('cursorPositionChanged()'), self.highlightCurrentLine)
왜 이것이 왜 작동하지 않는지에 대해 아는 사람이 있습니까?
내가 사용하는 버전은 다음과 같습니다. Python 2.6.2, Pyqt 4.4.4
해결책
좋아 ... 내가 화 내지 않았다.
정보를 위해 Ubuntu 9.04와 함께 제공되는 PYQT4의 버전은 4.4.4이지만이 기능은 4.5+가 필요한 것으로 보입니다.
나는 pyqt4 4.6으로 업그레이드했고 잘 작동합니다 (4.6은 새로운 기능이 좋은 것 같습니다).
다른 팁
구하다 lineColor
어딘가 (좋아요 self.lineColor
). 그렇지 않으면, 메소드가 돌아 오면 파이썬이 객체를 폐기하고 format
불법 포인터를 사용합니다.
제휴하지 않습니다 StackOverflow