PDA

View Full Version : setCursorPosition.



sar_van81
11th December 2006, 10:25
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...

wysota
11th December 2006, 10:41
Do you have more than one paragraph in your textEdit?

sar_van81
11th December 2006, 11:21
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...)

jpn
11th December 2006, 11:31
Take a look at QTextCursor::movePosition(). Here's an example of usage:


QTextCursor cursor = textEdit->textCursor();
cursor.movePosition(QTextCursor::NextBlock); // <--
textEdit->setTextCursor(cursor);

sar_van81
11th December 2006, 12:13
hi...

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

jpn
11th December 2006, 12:17
Yes, sorry. I was talking about Qt 4.

But how about QTextEdit::moveCursor() then? :)

sar_van81
11th December 2006, 13:25
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....?

sar_van81
11th December 2006, 13:28
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...

wysota
11th December 2006, 13:32
"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.

sar_van81
11th December 2006, 13:47
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...?

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

sar_van81
12th December 2006, 05:28
hi...

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