[Qt-interest] QTextEdit character offset

Keshava Krishna keshavkrishna88 at gmail.com
Tue Mar 17 10:44:50 CET 2009


Thank you  Stephen , your code worked out...
Regards,
Keshava.

On Sun, Mar 15, 2009 at 1:36 AM, Stephen Jackson <spjackson42 at gmail.com>wrote:

> On Sat, Mar 14, 2009 at 3:07 PM, Keshava Krishna wrote:
> >
> > I have been searching for function that can get me the starting and
> ending
> > offsets for 2 days now...
> > please help me people, I am in real trouble...
> >
> >>
> >> Hi,
> >>
> >> 'm building a text editor using QTextEdit, the user can scroll through
> the
> >> text document by using vertical scrollbar.
> >> i want to konw the offsets (character count) of the 1st and the last
> >> character that is currently visible in the Text Area. (even though the
> >> cursor position is not changed),
> >> Please suggest me a way to do it.
> >>
> >> Regards,
> >> Keshava.
> >
> >
>
> The following code is not perfect but it should point you in the right
> direction.
>
> For example, add the following function to the example in
> examples/assistant/simpletextviewer, plus a mechanism for calling it.
>
> void MainWindow::showPosition()
> {
>    QTextCursor cursor;
>    int position;
>    QString line;
>
>    cursor = textViewer->cursorForPosition ( QPoint(0,0)  );
>    position = cursor.position();
>    cursor.select(QTextCursor::LineUnderCursor);
>    line =  QString::number(position) + QString(", ") +
> cursor.selectedText();
>
>    QMessageBox::information(this, tr("Simple Text Viewer Start Position"),
>                            line);
>
>    // ----------------------------
>
>    cursor = textViewer->cursorForPosition (
> QPoint(textViewer->width(), ,textViewer->height())  );
>    position = cursor.position();
>    cursor.select(QTextCursor::LineUnderCursor);
>    line =  QString::number(position) + QString(", ") +
> cursor.selectedText();
>
>    QMessageBox::information(this, tr("Simple Text Viewer End Position"),
>                            line);
>
> }
>
>
> Hope this helps,
>
> Stephen Jackson
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090317/1a30a1f7/attachment.html 


More information about the Qt-interest-old mailing list