Results 1 to 12 of 12

Thread: setCursorPosition.

  1. #1
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default setCursorPosition.

    hi...

    can anyone say me how to move cursor position to next line using setCursorPosition...?

    in the textEdit, i tried entering text->setCursorPosition(1,0);(my current cursor postion is paragraph 0).

    but its not working...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setCursorPosition.

    Do you have more than one paragraph in your textEdit?

  3. #3
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: setCursorPosition.

    no... i have only a few lines in the paragraph.but its like this. i have a textedit's size as text->setGeometry(30,10,200,40 );

    its a small rectangle box.i dont want the scroll bars to appear.instead i'l click a pushbutton which should move the cursor to next line...(this is similar to functioning of the enter key in our keyboard...)

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setCursorPosition.

    Take a look at QTextCursor::movePosition(). Here's an example of usage:
    Qt Code:
    1. QTextCursor cursor = textEdit->textCursor();
    2. cursor.movePosition(QTextCursor::NextBlock); // <--
    3. textEdit->setTextCursor(cursor);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: setCursorPosition.

    hi...

    thanks for the reply.but i'm using qt-3.3.5. i think the class you said is in qt-4.2......

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: setCursorPosition.

    Yes, sorry. I was talking about Qt 4.

    But how about QTextEdit::moveCursor() then?
    J-P Nurmi

  7. #7
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: setCursorPosition.

    hi...

    yeah i found that. it works but not has that of our enter key....Also it works as our up down,back,forward arrows.i need to go the start of next line when i press the button...is it possible with the option setCursorPosition wherein we can place the cursor to the start of next line....?

  8. #8
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: setCursorPosition.

    i mean start of a new line. i used both QTextEdit::MoveDown and QTextEdit::MoveLineStart. the cursor only moves to existing line's start not to a new line...

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setCursorPosition.

    "Enter" does something else than just go to the start of next line. It inserts a "\n" character in the text and this is what causes it to go to the beggining of the line, there is no "going down one line" - that's only a side effect.

    If you want to mimic only the move itself, just use QTextEdit::MoveLineStart as the action for moveCursor() but if you don't have a line below, the cursor won't move because it doesn't have a place to move to - you have to add that new line there first.

  10. #10
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: setCursorPosition.

    hi....

    yeah exactly . i tried that only.i inserted "\n" when i press the button. when i enter characters, they are displayed in the next line,but the cursor still blinks in the above line only....thats where i got stuck. i'm trying to bring cursor also down... here is my code:

    void keyclass::enter()
    {
    str.append("\n");
    text->moveCursor(QTextEdit::MoveDown,0);
    text->moveCursor(QTextEdit::MoveLineStart,0);
    }

    str is a string . when i enter the keys in the keyboard(which i created, not the physicall connected keyboard), i'l store them in this string and display them in the textedit. so when i press enter i'l insert "\n" in the string . this causes the characters to go to the nextline while the cursor blinks in the previous. is this what u suggested...? or Am i missing something else...?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setCursorPosition.

    QTextEdit in Qt3 was somewhat buggy, so you might be experiencing some side effect.
    Maybe instead of placing \n you should use QTextEdit::insertParagraph()?

  12. #12
    Join Date
    Dec 2006
    Posts
    123
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: setCursorPosition.

    hi...

    its working successfully...thanks a lot to you and to everyone.....

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.