[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    [PyKDE] Inserting Rich Text in a QTextEdit
From:       Michael Sparks <zathras () thwackety ! com>
Date:       2004-12-20 2:42:58
Message-ID: Pine.LNX.4.44.0412200403300.29251-100000 () pingu ! thwackety ! com
[Download RAW message or body]

Hi,


I've been using a QTextEdit for a while as a simple rich text editor, and
recently been playing with various ideas and have hit a bit of a block.
Essentially what I want to do is this:

   editor.insert("<a href='"+str(page)+"'>"+str(page)+"</a>"  )

And have that rendered _and stored in the text_(*) as a hyperlink - ie the
above line results in (with defaults) "page" being rendered underlined in
blue.
   (*) Hence a stylesheet isn't an option here :-(

Instead however what I see in the editor is this:

  <a href='Somepage'>Somepage</a>

(Which gets saved as &lt;a href ... etc )

However, if I use this:

   editor.append("<a href='"+str(page)+"'>"+str(page)+"</a>"  )

This is correctly interpreted as being a hyperlink, and saved as a
hyperlink.

The question I have really is this - is there any way round this, short of
building up this behaviour from scratch doing something like:

(pseudocode)

   if hasSelectedText
      t = selectedText
      removeSelectedText
      p = getCursorPosition
      setCursorPosition(end of text)
      q = getCursorPosition
      append("thing I want")
      r= setCursorPosition(end of text)
      setSelection(between q and r)
      cut
      setCursorPosition(p)
      paste

?

It seems like a lot of faff ? (obviously I'd wrap that up in a function,
probably called something like insertRichText(), but even so... (I'd be
happy with a "replace selection" option instead, but I can't see that -
hopefully I'm being blind :) )

Failing that, if I really have missed something and there's a much simpler
way of doing this I'd really appreciate a pointer, slap round the head :)

Thanks for any responses,


Michael.

_______________________________________________
PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic