Adding new functionality to CodeEditor example
-
wrote on 11 Dec 2024, 17:55 last edited by
I've seen example of creating line numbers using QPlainTextEdit from here. But now i also want to draw lines between strings. My idea was to override
CodeEditor::paintEvent()
. So the question is: can i call -QPlainTextEdit::paintEvent()
fromCodeEditor::paintEvent()
to saveQPlainTextEdit::paintEvent()
functionality and then draw lines in it?
If not, what is the best way to achieve this? -
I've seen example of creating line numbers using QPlainTextEdit from here. But now i also want to draw lines between strings. My idea was to override
CodeEditor::paintEvent()
. So the question is: can i call -QPlainTextEdit::paintEvent()
fromCodeEditor::paintEvent()
to saveQPlainTextEdit::paintEvent()
functionality and then draw lines in it?
If not, what is the best way to achieve this? -
@Khamza
Yes, assuming you meanCodeEditor
inheritsQPlainTextEdit
. From your overriddenpaintEvent()
call the base one and then you could add your own extra drawing, if that is what you want to do. -
@JonB Yeah, it is. But i read that i should not call
paintEvent()
directly. Isn't this the case?wrote on 11 Dec 2024, 18:20 last edited by JonB 12 Nov 2024, 18:21@Khamza
You are not supposed to just callpaintEvent()
from somewhere else, it's designed to be called during actual painting. If you override a basepaintEvent()
you can (and should) indeed call the base implementation from there. -
1/4