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. Change in QTextLayout with Qt 6
QtWS25 Last Chance

Change in QTextLayout with Qt 6

Scheduled Pinned Locked Moved Unsolved General and Desktop
highlighttexteditformat
5 Posts 2 Posters 602 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
    Maluna34
    wrote on 18 Jan 2021, 18:56 last edited by Maluna34
    #1

    Hello,

    I'm using in a project a QSyntaxHighlighter with some unit tests on my class, in which I manually set text and check the formats by using:

    const auto formats = textEdit.textCursor().block().layout()->formats();
    

    With Qt 6, the formats sometimes include the newline.

    -> To see the difference, I just added this code to the Syntax Highlighter example of Qt (in the MainWindow constructor):

    auto w = new QWidget;
    auto l = new QHBoxLayout;
    auto p = new QPushButton("Click");
    
    l->addWidget(editor);
    l->addWidget(p);
    
    connect(p, &QPushButton::clicked, this, [this]() {
        editor->setPlainText("Here is /* a\n"
                             "multi-lines\n"
                             " comment in C++ */ !");
    
        // I check the second line
        const auto block = editor->textCursor().block().next();
        const auto formats = block.layout()->formats();
    
        qDebug() << "Block length:" << block.length() << "/" << block.text().count();
        qDebug() << "Format length:" << formats.first().start << "(" << formats.first().length << ")";
    });
    

    And here are the results:

    Qt 5.15

    Block length: 12 / 11
    Format length: 0 ( 11 )
    

    Qt 6.0

    Block length: 12 / 11
    Format length: 0 ( 12 )
    

    It seems that Qt takes into account the newline (and not for the first line ?).
    Does anyone have an explanation ?

    Thanks a lot!!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 Jan 2021, 19:18 last edited by
      #2

      Hi,

      There's something not clear. You say that it sometimes include the carriage return. Is it something that happens only in the specific case you found out ?

      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
      0
      • M Offline
        M Offline
        Maluna34
        wrote on 18 Jan 2021, 20:33 last edited by
        #3

        Hi and thanks for the reply!

        Yes, it seems. For the first line I correctly get 4 for the length.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Maluna34
          wrote on 19 Jan 2021, 09:59 last edited by
          #4

          Maybe a bug with Qt 6 ?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 8 Feb 2021, 12:59 last edited by
            #5

            Sorry for the late reply, it looks like there's indeed something changed in between.

            You should check the release notes just in case it was mentioned somewhere. If nothing, then please consider opening a new report on the bug report system if there's not already something there.

            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
            0

            • Login

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