Results 1 to 3 of 3

Thread: Saving QTextDocument line spacing for inner blocks to HTML file for further usage

  1. #1
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Saving QTextDocument line spacing for inner blocks to HTML file for further usage

    Greetings everyone. I'm writing WYSIWYG editor with Qt-4.8 Scribe framework. One of requirements is setting different line spacings for different text blocks. http://www.qtcentre.org/threads/4999...-QTextDocument thread gave me a solution: usage of QTextBlockFormat::setLineHeight(). It works fine but when I save a document with QTextDocumentWriter line spacing is not saved. See picture and code below.

    Image:
    spacings.jpg

    Resulting HTML code (within <body> tag):
    Qt Code:
    1. <body style=" font-family:'Times New Roman'; font-size:12pt; font-weight:400; font-style:normal;">
    2. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Single spacing:</p>
    3. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq</p>
    4. <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
    5. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">One and a half spacing:</p>
    6. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq</p>
    7. <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
    8. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Double spacing:</p>
    9. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq</p></body>
    To copy to clipboard, switch view to plain text mode 

    As you can see, there is no properties like "line-height" within <p style"=..."> tags as well as in http://doc.qt.io/qt-4.8/richtext-html-subset.html (Supported HTML subset). Here is code that sets line spacing:

    Qt Code:
    1. QTextBlockFormat fmt = cursorToHandle.blockFormat();
    2. fmt.setLineHeight(c_spacing, QTextBlockFormat::ProportionalHeight); // c_spacing is 100 for single, 150 for 1.5 and 200 for double
    3. cursorToHandle.setBlockFormat(fmt);
    To copy to clipboard, switch view to plain text mode 

    Here is code that saves document:

    Qt Code:
    1. QString strDocHtml = m_pDoc->toHtml();
    2. QSharedPointer<QFile> pFile(new QFile(c_strFilePath));
    3. if (!pFile->open(QIODevice::WriteOnly))
    4. {
    5. return false;
    6. }
    7. return pFile->write(strDocHtml.toStdString().c_str());
    To copy to clipboard, switch view to plain text mode 

    Here is code for loading:

    Qt Code:
    1. QFile file(c_strFilePath);
    2. if (!file.open(QFile::ReadOnly))
    3. {
    4. return false;
    5. }
    6.  
    7. QByteArray data = file.readAll();
    8. QTextCodec* pCodec = Qt::codecForHtml(data);
    9. QString strRawHtml = pCodec->toUnicode(data);
    10.  
    11. m_pDoc->setHtml(strRawHtml);
    12. }
    To copy to clipboard, switch view to plain text mode 

    So the question is: is there any way to save line spacings to *.html file and read it again?

    If any additional information is necessary I'll be glad to provide it.

    Thanks in advance.

  2. #2
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QTextDocument line spacing for inner blocks to HTML file for further usage

    Well, seems like it is bug of sorts, because there is no mentions about line-edit block property in documentation. Reported here about this issue.

  3. #3
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving QTextDocument line spacing for inner blocks to HTML file for further usage

    Is there any ability to mark this thread as solved?

Similar Threads

  1. Replies: 1
    Last Post: 8th October 2015, 12:11
  2. Replies: 4
    Last Post: 13th February 2012, 19:09
  3. Replies: 1
    Last Post: 25th May 2011, 20:25
  4. QTextDocument - line spacing
    By mazurekwrc in forum Qt Programming
    Replies: 5
    Last Post: 25th February 2011, 00:23
  5. Special characters in Html blocks
    By giusepped in forum Qt Programming
    Replies: 4
    Last Post: 27th October 2008, 09:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.