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

Justifying with tab spaces in the text



  • Hey,

    I'm creating a text editor and I am implementing the text alignments. All works fine except when justifying text with some tabs in it, for instance :

    "this is a a tab space"

    My code is quite simple :

    void setJustifyText(bool jusitfy)
    {
        QTextBlockFormat format;
        format.setAlignment(justify ? Qt::AlignmentFlag::AlignJustify : Qt::AlignmentFlag::AlignAbsolute);
        cursor.mergeBlockFormat(format);
    }
    

    And the error I get from Microsoft Visual Studio is :

    Debug Error!
    Program Qt\5.12.5\mscvc2017\bin\Qt5Cored.dll
    Module: 5.12.5
    File: text\qtextlayout.cpp
    Line:1780

    ASSERT: "(pos == end && glyphPosition == current.num_glyphs) || logClusters[pos] == glyphPosition" in file text\qtextlayout.cpp, line 1780

    Thanks for any help! I tried finding something in relation to this problem already on forums, but I didn't really find any proper solution to my problem.


  • Qt Champions 2019

    @Horia "Modifies the block format of the current block (or all blocks that are contained in the selection) with the block format specified by modifier." - is there a block or selection when you're calling this?



  • @jsulm Hey and thanks for the reply, yes there is a proper selection with the cursor for the selected block/blocks in the selection.

    To be noted that justifying works fine without any tabs in the text, selection is handled properly.


Log in to reply