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. No examples found on how to derive from QAbstractTextDocumentLayout
QtWS25 Last Chance

No examples found on how to derive from QAbstractTextDocumentLayout

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 811 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.
  • J Offline
    J Offline
    jkdoug
    wrote on last edited by
    #1

    I've been playing with QTextDocument a lot recently, trying all the different methods of rendering the rich text data. The document's draw method is useful for a text editor, but I'm making a custom display that works for text-based games (Telnet servers). I was rendering the whole document and then translating the painter to "scroll up" the canvas. It was very slow, as you can imagine.

    I am currently using QTextLayout do draw from the last QTextBlock up the window until the coordinates are out of view. This works much, much faster, and I'm pleased with the results.
    @ QRectF r(rect());

    int y = r.height();
    
    QTextBlock textBlock(m_document->lastBlock());
    while (y > 0 && textBlock.isValid())
    {
        QTextLayout textLayout(textBlock);
        textLayout.setCacheEnabled(true);
    
        textLayout.beginLayout();
    
        QList<QTextLine> lines;
        QTextLine line(textLayout.createLine());
        while (line.isValid())
        {
            line.setLineWidth(r.width());
            y -= line.height();
            lines.append(line);
    
            line = textLayout.createLine();
        }
    
        int lineY = y;
        foreach (line, lines)
        {
            line.setPosition(QPointF(0, lineY));
            lineY += line.height();
        }
    
        textLayout.endLayout();
    
        textLayout.draw(&painter, QPoint(0, 0));
    
        textBlock = textBlock.previous();
    }
    

    @

    Now, I'm faced with the problem of trying to calculate coordinates for mouse events, set up selections, change formats, and all the more advanced stuff. Changing to the implementation of a proper layout derived from QAbstractTextDocumentLayout seems like the way to move forward, but this is proving to be a monumental task... because so much of the implementation used by Qt itself is made inaccessible to the end user.

    Could someone give me a helping hand or point me in the right direction before I try to re-implement all the Qt private code and adapt it to my needs?

    1 Reply Last reply
    0
    • TrilecT Offline
      TrilecT Offline
      Trilec
      wrote on last edited by
      #2

      Hi Sorry no one responded.
      Ive been looking also into this also you could try (or those searching this topic)

      KoTextDocumentLayout.h
      KoTextDocumentLayout.cpp

      https://github.com/JeremiasE/KFormula/blob/gsoc/libs/kotext/KoTextDocumentLayout.cpp

      If ts not in the computer it doesn't exist!...

      1 Reply Last reply
      3

      • Login

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