Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-107221

There is no way to reliably copy the contents of one QTextDocument into another QTextDocument

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.4.0
    • GUI: Text handling
    • None

    Description

      If I want to insert the entire contents of one QTextDocument into another, or turn one QTextDocument into a copy of another.

      Using QTextCursor::select to select the entire document and then QTextCursor::selection to get a fragment works when the document contains text, but not when the document is empty. Furthermore QTextCursor::selection doesn't include properties of the QTextDocument like its indent width or default font.

      Ideally there would be a function like QTextDocument::copy(QTextDocument*) that would cause the calling document to copy all of the properties, contents and formatting of the argument document. Alternatively something like QTextCursor::insertDocument(QTextDocument*) would also work, where the cursor inserts the contents and formatting of the argument document into the document it is modifying, though this method wouldn't be able to affect the properties of the QTextDocument.

      To help illustrate the problem I'm describing I'll add an example:

      #include <QCoreApplication>
      #include <QTextDocument>
      #include <QTextCursor>
      #include <QTextList>
      #include <QTextDocumentFragment>
      
      int main(int argc, char *argv[])
      {
      	QCoreApplication a(argc, argv);
      	QTextDocument doc;
      	QTextCursor cursor(&doc);
      	cursor.createList(QTextListFormat::ListDecimal);
      	qDebug() << doc.toHtml(); // This will output the html containing the list
      	cursor.select(QTextCursor::Document);
      	qDebug() << cursor.selection().toHtml(); // This output will be empty
      	return a.exec();
      }
      

      If you look in the output you'll see that the document contains a list, but the cursor's selection doesn't. This means that it isn't possible to copy that list from one document into another.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            camilo Dave Erified
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes