[Qt-interest] How to user QTextBlockUserData?
程梁
chengliang.soft at gmail.com
Mon Jan 3 02:17:57 CET 2011
Thank you, Diego! I can do it follow your instructions!
> I have read that using QtWebKit it will be easier. No idea how to
implement
I know it is easy to embed an existing online WYSIWYG editor with QtWebkit.
Or you can write it in your own way. It doesn't matter. The key code is
javascript's statement execCommand() function. Maybe you can google if you
are interesting (or just read it from
here<https://developer.mozilla.org/en/rich-text_editing_in_mozilla>).
But it is not easy to do well because you have to be familiar with
javascript, too. And Qt need to execute javascript in function
QWebFrame::evaluateJavaScript(const QString &), as you can see, javascript
is treated as string so it is not easy to debug.
> PS: can you share code when it's done?
If you mean the editor code, yes. And I set it as an open source project
named OrbitsWriter at sourceforge
here<https://sourceforge.net/projects/orbitswriter/>.
It is just in the beginning so there is no package to download. But you can
clone the whole code from mercurial is you want. ;-P
2011/1/3 Diego Iastrubni <diegoiast at gmail.com>:
> 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 use
> QTextCursor::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?
--
Cheng Liang
from: chengliang.soft at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110103/e71b5536/attachment.html
More information about the Qt-interest-old
mailing list