Writing an IDE with Qt6
-
I'm currently attempting to write an IDE with Qt6 and running into a lot of conceptual issues with the way
QTextDocument
and theQQuickTextEdit
operate.The documentation basically splits my option into two, either use the
QTextBlock
s or theQTextFrame
s for breaking chunks of code into code blocks. I'd really like to do that so I can actually add contextual information for variables for example. These are hierarchically structured, hence I'd opt for theQTextFrame
api. However, several issues here: First of all I can't attach metadata to a text frame. No way to attach information means no way to store and retrieve information, meaning they're basically useless. It doesn't end here, the only way to add text frames to a document is using theQTextCursor
api, usingQTextCursor::insertFrame
. The only parameter here is a format, which makes it impossible to order the frames in a hierarchical way, even though they're praised as one? I'm severely confused by this, so my question here basically is: How are you even supposed to use them, if the api doesn't support what it says?The second option would be to group code blocks into text blocks. Let that image of the text view speak for itself:
This was generated by the following code:QTextCursor cursor(document); cursor.movePosition(QTextCursor::MoveOperation::Start); cursor.insertText("public class Point\n"); cursor.insertBlock(); cursor.insertText("{\n public int X "); cursor.insertBlock(); cursor.insertText("{ get; set; "); cursor.insertBlock(); cursor.insertText("}\n\n public int Y "); cursor.insertBlock(); cursor.insertText("{ get; set; "); cursor.insertBlock(); cursor.insertText("}\n"); cursor.insertBlock(); cursor.insertText("}\n");
So, fair to say that code blocks aren't gonna be a help here either. It doesn't end with this, the fact that there's no way for me to create a
QQuickTextDocument
from a plain oldQTextDocument
means that I don't even have the ability to cache or preprocess documents for anything, which wouldn't be such a great deal but it's unfortunate. I'm sensing that the API is lacking severely for this use-case (and don't get me started with the QSyntaxHighlighter that only supports forward updates and no way to access the state of previous and next user data which would be required for such use cases. However writing my own version of this class wasn't too hard).Is anybody here experienced enough with these classes to tell me how to head in the right direction, even if that means implementing this all by myself with a custom text edit, document and layout code? Thanks in advance
-
I'm currently attempting to write an IDE with Qt6 and running into a lot of conceptual issues with the way
QTextDocument
and theQQuickTextEdit
operate.The documentation basically splits my option into two, either use the
QTextBlock
s or theQTextFrame
s for breaking chunks of code into code blocks. I'd really like to do that so I can actually add contextual information for variables for example. These are hierarchically structured, hence I'd opt for theQTextFrame
api. However, several issues here: First of all I can't attach metadata to a text frame. No way to attach information means no way to store and retrieve information, meaning they're basically useless. It doesn't end here, the only way to add text frames to a document is using theQTextCursor
api, usingQTextCursor::insertFrame
. The only parameter here is a format, which makes it impossible to order the frames in a hierarchical way, even though they're praised as one? I'm severely confused by this, so my question here basically is: How are you even supposed to use them, if the api doesn't support what it says?The second option would be to group code blocks into text blocks. Let that image of the text view speak for itself:
This was generated by the following code:QTextCursor cursor(document); cursor.movePosition(QTextCursor::MoveOperation::Start); cursor.insertText("public class Point\n"); cursor.insertBlock(); cursor.insertText("{\n public int X "); cursor.insertBlock(); cursor.insertText("{ get; set; "); cursor.insertBlock(); cursor.insertText("}\n\n public int Y "); cursor.insertBlock(); cursor.insertText("{ get; set; "); cursor.insertBlock(); cursor.insertText("}\n"); cursor.insertBlock(); cursor.insertText("}\n");
So, fair to say that code blocks aren't gonna be a help here either. It doesn't end with this, the fact that there's no way for me to create a
QQuickTextDocument
from a plain oldQTextDocument
means that I don't even have the ability to cache or preprocess documents for anything, which wouldn't be such a great deal but it's unfortunate. I'm sensing that the API is lacking severely for this use-case (and don't get me started with the QSyntaxHighlighter that only supports forward updates and no way to access the state of previous and next user data which would be required for such use cases. However writing my own version of this class wasn't too hard).Is anybody here experienced enough with these classes to tell me how to head in the right direction, even if that means implementing this all by myself with a custom text edit, document and layout code? Thanks in advance
@MansenC said in Writing an IDE with Qt6:
QTextDocument and the QQuickTextEdit
I don't think these two are good to implement a proper text editor for an IDE.
You can take a look at https://qscintilla.com/# -
@MansenC said:
First of all I can't attach metadata to a text frame
QTextFrame derives from QObject, so you can attach any information you want using setProperty API.
The only parameter here is a format, which makes it impossible to order the frames in a hierarchical way
When you get a new QTextFrame you can call its firstCursorPosition or lastCursorPosition to get a cursor inside that frame, and you can use that cursor to insert another frame inside. That would build a hierarchy right?
-
@Chris-Kawa said:
QTextFrame derives from QObject, so you can attach any information you want using setProperty API.
Completely overlooked that, thanks
When you get a new QTextFrame you can call its firstCursorPosition or lastCursorPosition to get a cursor inside that frame, and you can use that cursor to insert another frame inside. That would build a hierarchy right?
Didn't see that from the documentation, but that should work. Although I cannot figure out how to select things properly to define the length of a TextFrame. However after reading the documentation again I saw that every TextFrame inserts a separate TextBlock, which results in the behaviour from my screenshot, just with more empty lines behind it. So they are completely useless again, great.
@jsulm said:
I don't think these two are good to implement a proper text editor for an IDE.
You can take a look at https://qscintilla.com/#Looks like that's my only option, even though I wanted to keep things as flexible as possible for me and I have the parsing done for C# already. That's annoying, plus it has support for many languages, except the two I need currently - Java and C#...
-
@Chris-Kawa said:
QTextFrame derives from QObject, so you can attach any information you want using setProperty API.
Completely overlooked that, thanks
When you get a new QTextFrame you can call its firstCursorPosition or lastCursorPosition to get a cursor inside that frame, and you can use that cursor to insert another frame inside. That would build a hierarchy right?
Didn't see that from the documentation, but that should work. Although I cannot figure out how to select things properly to define the length of a TextFrame. However after reading the documentation again I saw that every TextFrame inserts a separate TextBlock, which results in the behaviour from my screenshot, just with more empty lines behind it. So they are completely useless again, great.
@jsulm said:
I don't think these two are good to implement a proper text editor for an IDE.
You can take a look at https://qscintilla.com/#Looks like that's my only option, even though I wanted to keep things as flexible as possible for me and I have the parsing done for C# already. That's annoying, plus it has support for many languages, except the two I need currently - Java and C#...
@MansenC said:
I cannot figure out how to select things properly to define the length of a TextFrame
By length you mean cursor position difference in the document?
That would beint length = frame->lastPosition() - frame->firstPosition()
.which results in the behaviour from my screenshot, just with more empty lines behind it
I guess that's where the format argument comes in. You can use QTextFrameFormat::setMargin() to remove any extra spacing you don't want.
-
@Chris-Kawa said:
By length you mean cursor position difference in the document?
Not quite, I meant setting the selection in the document/frame so I can create a frame with that first and last position. I figured that out though, no need for that anymore.
I guess that's where the format argument comes in. You can use QTextFrameFormat::setMargin() to remove any extra spacing you don't want.
I can do that, but I don't think it's quite right. I need multiple text blocks or text frames on one line, and it's not naturally supported. Moving them with the margins into a single line does work, but creates very confusing text navigation and makes for a wrong line/character count unfortunately
-
Hi,
You might want to check KDE's KTextEditor as well.