[Qt-interest] Wrapping text around picture in QTextEdit

Girish Ramakrishnan girish at forwardbias.in
Thu Oct 13 10:10:04 CEST 2011


Hi Dmitry,

On Thu, Oct 13, 2011 at 1:26 AM, Dmitry Fomin <fomin.dm at gmail.com> wrote:
> Hello everyone!
>
> I'm developing a WYSIWYG editor using QTextEdit. I need to support
> text wrapping around pictures, but it seems that QTextEdit does not
> support that.
> I tried to use QTextLayout for this and lay out text manually in
> paintEvent(), but text gets uneditable.
> I tried to insert pucture using html, but html subset of QTextDocument
> doesn't support 'position' for attribute 'style' in <img> tag.
> Components with full html and css support don't support editing.

QtWebKit supports editing html content with designMode and
contentEditable DOM attributes. Also, see
QWebPage::setContentEditable().

> I thought about implementing QAbstractTextDocumentLayout subclass, but
> it seems to be a very hard task, while, for example,
> QPlainTextDocumentLayout implementation providing simpler text layout
> consists of 2.7K lines of code.
> I tried to insert a picture in QTextFrame, but QTextFrame cannot be
> moved to specific position.
> I investigated source code of KWord, but it's very complex; I suppose
> KWord uses its own system for laying out document items.
> I would like to have something like this -
> http://dl.dropbox.com/u/6880232/1.png - but with editing option. I get
> this by simply inserting an image to QTextEdit as a special character:
> http://dl.dropbox.com/u/6880232/2.png.
> Are there accessible solutions for this task? What could you suggest
> for implementing the editor?
>

Floating is already supported in QTextEdit. Have you tried
http://doc.qt.nokia.com/stable/qtextcursor.html#insertImage-2 ?

Girish



More information about the Qt-interest-old mailing list