Syntax highlighting in a QLineEdit
-
Is there a way to have syntax highlighting in a
QLineEdit
? Some markdown thing
When I say syntax highling I mean something likeclass X:
in a
QLineEdit
. I have given up on trying to do this in aQTextEdit
because the markdown worked but didnt show the colours.
QTextEdit
also doesn't have theQCompleter
which is necessary for me.
So I have resorted to chaining lots ofQLineEdits
without the border and padding so it looks like oneQTextEdit
. Again, probably with scrolling but it will have to do.
I say this incase anyone has any answers to these problems withQTextEdit
. -
QSyntaxHighlighter
is an abstract class that provides the highlighting interface. You can't instantiate it.
You need to inherit it and provide your implementation of that interface.Took me 5s of googling to find an implementation for Python: MarkdownHighlighter. It even supports custom themes.
-
Is there a way to have syntax highlighting in a
QLineEdit
? Some markdown thing
When I say syntax highling I mean something likeclass X:
in a
QLineEdit
. I have given up on trying to do this in aQTextEdit
because the markdown worked but didnt show the colours.
QTextEdit
also doesn't have theQCompleter
which is necessary for me.
So I have resorted to chaining lots ofQLineEdits
without the border and padding so it looks like oneQTextEdit
. Again, probably with scrolling but it will have to do.
I say this incase anyone has any answers to these problems withQTextEdit
.@Caeden said:
So I have resorted to chaining lots of QLineEdits without the border and padding so it looks like one QTextEdit
That's like having an array of one letter strings instead of a single string. That's horrible, don't do that!
Is there a way to have syntax highlighting?
There's a QSyntaxHighlighter that is used to color text documents. There's no built-in markdown highlighter provided by Qt though, so you have to implement one yourself. Example: Syntax Highlighter Example. There's probably some existing 3rd party implementation too. Just google it.
QTextEdit also doesn't have the QCompleter which is necessary for me.
It doesn't use one out of the box, but nothing is stopping you from adding it. Example: Custom Completer Example.
Or you can go the lazy way and just use some 3rd party widget like this one.
-
@Caeden said:
So I have resorted to chaining lots of QLineEdits without the border and padding so it looks like one QTextEdit
That's like having an array of one letter strings instead of a single string. That's horrible, don't do that!
Is there a way to have syntax highlighting?
There's a QSyntaxHighlighter that is used to color text documents. There's no built-in markdown highlighter provided by Qt though, so you have to implement one yourself. Example: Syntax Highlighter Example. There's probably some existing 3rd party implementation too. Just google it.
QTextEdit also doesn't have the QCompleter which is necessary for me.
It doesn't use one out of the box, but nothing is stopping you from adding it. Example: Custom Completer Example.
Or you can go the lazy way and just use some 3rd party widget like this one.
@Chris-Kawa These seem very useful but they're for C++ as far as I am aware
For example;
When I useself.highlighter = QtGui.QSyntaxHighlighter(self.code_input.document())
Gives me an error of
TypeError: PyQt5.QtGui.QSyntaxHighlighter represents a C++ abstract class and cannot be instantiated
And I can't see a lazy 3rd party widget for
PyQt
-
QSyntaxHighlighter
is an abstract class that provides the highlighting interface. You can't instantiate it.
You need to inherit it and provide your implementation of that interface.Took me 5s of googling to find an implementation for Python: MarkdownHighlighter. It even supports custom themes.
-
After further research on the markdown highlighter I seem to have a way to highlight my code. Thank you so much for this, you're a hero.