Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Writing an IDE with Qt6
QtWS25 Last Chance

Writing an IDE with Qt6

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 771 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MansenC
    wrote on last edited by
    #1

    I'm currently attempting to write an IDE with Qt6 and running into a lot of conceptual issues with the way QTextDocument and the QQuickTextEdit operate.

    The documentation basically splits my option into two, either use the QTextBlocks or the QTextFrames 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 the QTextFrame 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 the QTextCursor api, using QTextCursor::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:
    TextView not being a help in this issue
    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 old QTextDocument 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

    jsulmJ 1 Reply Last reply
    0
    • M MansenC

      I'm currently attempting to write an IDE with Qt6 and running into a lot of conceptual issues with the way QTextDocument and the QQuickTextEdit operate.

      The documentation basically splits my option into two, either use the QTextBlocks or the QTextFrames 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 the QTextFrame 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 the QTextCursor api, using QTextCursor::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:
      TextView not being a help in this issue
      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 old QTextDocument 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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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/#

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MansenC
          wrote on last edited by
          #4

          @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 KawaC 1 Reply Last reply
          0
          • M MansenC

            @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 KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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 be int 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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MansenC
              wrote on last edited by
              #6

              @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

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                You might want to check KDE's KTextEditor as well.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved