Qt-interest Archive, February 2007
how to know in qtextedit Qt4 where user click
Message 1 in thread
Hi,
I don't find in qtextedit classes the right way to know where the user
click in the document?
a text :
zzadfsdfsdfsqdf qsdfsdf aa bb aqfqsfg
the cursor is after last letter when user click between the two a letters.
In event filter I should be able to know that user clicked and where in
the block (or textcursor) .
Is someone know how to get position of cursor in a block?
--
[ signature omitted ]
Message 2 in thread
veronique.lefrere@xxxxxx wrote:
> Is someone know how to get position of cursor in a block?
QTextCursor cursorThing = Editor->textCursor();
int editorPosition = cursorThing.position();
--
[ signature omitted ]
Message 3 in thread
Forrest a écrit :
> veronique.lefrere@xxxxxx wrote:
>
>> Is someone know how to get position of cursor in a block?
>
>
> QTextCursor cursorThing = Editor->textCursor();
> int editorPosition = cursorThing.position();
>
position return the absolute position in the document, not in the block.
I would like to be able to translate position in document to position in
text block
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Message 4 in thread
veronique.lefrere@xxxxxx wrote:
> I would like to be able to translate position in document to position in
> text block
QTextCursor cursorThing = Editor->textCursor();
QTextBlock ourBlock = cursorThing.block();
int ourPos = cursorThing.position() - ourBlock.position();
// offset into block
...and just for fun, get the line number within the block...
QTextLayout * ourLayout = ourBlock.layout();
if (ourLayout->isValidCursorPosition(ourPos))
{
QTextLine ourLine = ourLayout->lineForTextPosition(ourPos);
if (ourLine.isValid())
{ ourLineNumberOffset = ourLine.lineNumber(); }
}
int whatsMyLine = 1 + preCursorLines + ourLineNumberOffset;
...which can be added to the number of lines in the blocks above the
current block in order to get the absolute line number.
--
[ signature omitted ]
Message 5 in thread
ok,
thank you for help,
I didn't see the QTextLayout and begin to understand how to manipulate
textdocument classes...
have a nice day.
Veronique.
Forrest a écrit :
> veronique.lefrere@xxxxxx wrote:
>
>> I would like to be able to translate position in document to position
>> in text block
>
>
>
> QTextCursor cursorThing = Editor->textCursor();
> QTextBlock ourBlock = cursorThing.block();
> int ourPos = cursorThing.position() - ourBlock.position();
> // offset into block
>
>
>
> ...and just for fun, get the line number within the block...
>
> QTextLayout * ourLayout = ourBlock.layout();
> if (ourLayout->isValidCursorPosition(ourPos))
> {
> QTextLine ourLine = ourLayout->lineForTextPosition(ourPos);
> if (ourLine.isValid())
> { ourLineNumberOffset = ourLine.lineNumber(); }
> }
> int whatsMyLine = 1 + preCursorLines + ourLineNumberOffset;
>
>
> ...which can be added to the number of lines in the blocks above the
> current block in order to get the absolute line number.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]