[Qt-interest] How to user QTextBlockUserData?

Diego Iastrubni diegoiast at gmail.com
Sun Jan 2 19:52:57 CET 2011


Hi Cheng Liang,

On Mon, Dec 27, 2010 at 5:35 PM, 程梁 <chengliang.soft at gmail.com> wrote:

> Hi, there! I wounder how can I use class QTextBlockUserData?
>
> I'm trying to develop an HTML editor using QTextEdit as a visual
> editor. The HTML text
> generated by QTextEdit is related to Qt itself, so I have to generate
> simpler HTML text
> myself instead of using QTextEdit::toHtml(). I want to store css or
> other data in QTextBlockUserData
> which can be related to QTextBlock. But I've no idea how to use it.
>

You just need to inherit it

class MyBlockData: public QTextBlockUserData{
   ...
}

and then you can read it. You can read it using (for example):

MyBlockData *data = dynamic_cast<MyBlockData*> (
document()->firstBlock()->userData());
if (data!=NULL) {
   ...
}


> QTextCursor::insertBlock();
> returns void; QTextCursor::block() returns QTextCursor's copy, not a
> reference or a pointer.
>


> Although there is the function QTextBlock::setUserData(), but how can
> I add the data?
>

See above, maybe it will give you an idea. And yes, you can
useQTextCursor::block(),it will point to the correct block. Don't
worry.

Or some idea about developing an HTML editor?
>

I have read that using QtWebKit it will be easier. No idea how to implement
it.

PS: can you share code when it's done?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110102/486c7050/attachment.html 


More information about the Qt-interest-old mailing list