Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Manipulating characters within a QTextDocument/QAbstractTextDocumentLayout



  • Hi All,
    Im trying to find a creative solution to adding characters that are not editable to the outside of text blocks and potentially changing the "look" (UPPERCASE, ITALIC etc.) in a QTextEdit. The original text must stay the same as the user can switch to different views, however the printing should take into account the "view" settings .

    Use case: (User selects the "type of text" from a drop-down)

    • Normal
    • Brackets
    • Uppercase

    if "Bracket" is selected, the user is presented a margin indented start and end bracket [] with entry cursor set in the middle, the user cant remove the brackets but any text entry expands the brackets and when an enter key detected the next line is set to normal. eg: "TITLE: [ user text is here ]"

    If "Uppercase" is selected ,All text entry (until enter key) is "displayed" as uppercase,but if the type is changed to normal the original case is preserved. eg: "USER TEXT IS HERE" original "User Text is HERE"

    Edit*
    Seems the QAbstractTextDocumentLayout is one possible solution, but has anyone used this for this kind of use case and perhaps has examples or some advice?.

    As usual, appreciate any pointers in the right direction.


  • Lifetime Qt Champion

    Hi,

    Are you looking to implement something like markdown ?



  • @SGaist said in manipulating characters within a QTextDocument:

    markdown

    Yes it could be the internals, but the view is the area of interest for me , how to handle this
    I suppose syntax could be:
    <BLOCKUPPER>User Text HERE</BLOCKUPPER> : OUTPUT = USER TEXT HERE
    <BLOCKBRACKET>Editable Text Here</BLOCKBRACKET> : OUTPUT = [ Editable Text Here ]
    <BLOCKHEADING>NONEDITABLE-TITLE:</BLOCKHEADING><BLOCKBRACKET>Editable Text Here</BLOCKBRACKET> : OUTPUT = NONEDITABLE-TITLE: [ Editable Text Here ]

    ..or something like this, the key issue is the various BLOCK definitions have different behavior of whats editable and whats not, hope that clarifies.
    The docs start to get fuzzy around this, QTextDocument, QAbstractTextDocumentLayout , QTextBlock etc
    with no clear examples of adding new markups thus leaving me confused where to start with concepts on how to deal with adding non editable text.

    Looking at the forum there seems minimal information for QAbstractTextDocumentLayout.
    ..Has ANYONE got a pointer to examples of using this??
    QTextDocmentLayout and QPlaintTextEdit have some small private API usage but more advanced seems VERY hard to find
    cheers


Log in to reply