[Qt-interest] Cursor in QWebPage?

Eric Clark eclark at ara.com
Wed Nov 18 18:34:20 CET 2009


Thank you Strahinja! Although, I would hate to have to work with javascript, arrrgghhh! I found a small work around  for what I was trying to do. Basically, I wanted to be able to insert text (or html) at the current position of the cursor, or over the current selection. The work around that I found was to put my text into the clipboard and do a paste. This works brilliantly! Although, it seems a little bit like a kludge to me.

What I don't understand is why QWebPage does not inherit QTextDocument. If it did, it would be much easier to manipulate the editable text using a QTextCursor. At any rate, I have not heard anything back from any of the trolltech guys, so I guess it is not a big concern to them. I do appreciate your response though!

Eric

> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Strahinja Markovic
> Sent: Tuesday, November 17, 2009 5:23 PM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Cursor in QWebPage?
> 
> Eric Clark wrote:
> 
> > Hello All,
> >
> > I was wondering if anyone knew of any way to get the position of the
> text
> > cursor in an editable QWebPage? I would prefer the index in the text
> > document, but I can probably get that if I knew the point on the
> screen.
> > Maybe there is a way to manipulate a QWebPage or QWebFrame with a
> > QTextCursor? If not, can anyone tell me if there is any plan to
> implement
> > something like that?
> >
> > Thanks,
> > Eric
> 
> The best thing I can come up with is to use JavaScript. AFAIK you
> cannot do
> this with just the Qt API.
> 
> For the JavaScript, look at these pages on the Mozilla Developer
> Center:
> https://developer.mozilla.org/en/DOM/selection
> https://developer.mozilla.org/en/DOM/range
> 
> So you can get the Range object representing the current selection with
> "range =  window.getSelection().getRangeAt(0);". If the user hasn't
> selected
> anything and there is only a blinking cursor (actually called a
> _caret_),
> you will get a collapsed range (a range with the start and end points
> in the
> same place).
> 
> The collapsed range will only get you the char offset from the
> beginning of
> the current text node... from there, you can get the offset from the
> beginning of the document through a lot of JavaScript hardship. Make
> your
> life a bit easier and embed jQuery too.
> 
> Just FYI, you're in for a world of hurt. :)
> 
> BTW you run JS with this function:
> http://doc.trolltech.com/4.5/qwebframe.html#evaluateJavaScript
> 
> Sincerely,
> 
> Strahinja Markovic
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list