I've been building a GUI with a QTextEdit object and I want to add a QPushButton that moves the cursor down to a new line.
Edit: Someone suggested this question might answer mine: Moving the cursor in a PyQt5 text edit doesn't work
But it doesn't because after crashing my program the debugger says "QTextCursor object has no attribute 'Left'." In the comments under that answer it says to try "setTextCursor" but again... same issue.
Edit: Updated example
class Window(QWidget):
def __init__(self):
super().__init__()
self.layout = QVBoxLayout()
self.w = QTextEdit()
self.cursor = self.w.textCursor()
self.button = QPushButton('Button')
self.button.clicked.connect(self.nextBlock)
# Add to layout
self.layout.addWidget(self.button)
self.layout.addWidget(self.w)
self.setLayout(self.layout)
def nextBlock(self):
self.w.moveCursor(QTextCursor.NextBlock)
QTimer.singleShot(0, self.w.setFocus)
def main():
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()