PDA

View Full Version : How to add a new word to QTextEdit with "append"



yagabey
3rd January 2008, 13:28
Hello,

How can i append a line or word in QTextEdit with append(or another way) without making a new paragraph.I mean;
let's say in QTextEdit we have "Hello":

Hello

I wanna add "world":


textEdit->append("world")

will give the result:


Hello
world

but i want:


Hello world

jpn
3rd January 2008, 13:36
Like QTextExit::append() docs say, it appends a new paragraph. Use QTextEdit::moveCursor(QTextCursor::End) and QTextEdit::insertHtml() or QTextEdit::insertPlainText() instead.

ashukla
4th January 2008, 07:20
Like QTextExit::append() docs say, it appends a new paragraph. Use QTextEdit::moveCursor(QTextCursor::End) and QTextEdit::insertHtml() or QTextEdit::insertPlainText() instead.
Dear JPN!
I am using a format() function

void dlgTextScroller::format()
{
QTextCharFormat format;
QBrush brush(QImage::QImage("rose.jpg"));
brush.setStyle(Qt::TexturePattern);

format.setForeground(brush);

QTextCursor cursor = txtScrollEdit->textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::Document);
cursor.setCharFormat(format);
txtScrollEdit->setCurrentCharFormat(format);
}
for formatting the txtScrollEdit Text.
then for Animation of formatted text I am using;

QGraphicsTextItem *scrItem = new QGraphicsTextItem;
scrItem->setDocument(txtScrollEdit->document());
In this case my text appears as
Hello
worldHow to gain formatted text for animation in one line.

jpn
4th January 2008, 08:18
In this case my text appears as
Hello
worldHow to gain formatted text for animation in one line.
Umm, what does the code you pasted have to do with this? I don't see anything that appends or inserts any text at all. All I see is some formatting which applies a texture.

ashukla
4th January 2008, 08:32
Umm, what does the code you pasted have to do with this? I don't see anything that appends or inserts any text at all. All I see is some formatting which applies a texture.
Dear Sir!
I want to animate txtScrollEdit texture formatted text in


QGraphicsTextItem *scrItem = new QGraphicsTextItem;
scrItem->setDocument(txtScrollEdit->document());
When Iwrite text using with 36 point font size It goes to next line. And thats the reason when I setDocument() using with above scrItem it goes on the next line. However I want to animate formatted texture text as same as


QGraphicsTextItem *scrItem = new GraphicsTextItem(txtScrollEdit->toPlainText());
in a single line.

jpn
4th January 2008, 08:35
Have you tried to play with QGraphicsTextItem::setTextWidth()?

ashukla
4th January 2008, 08:49
Have you tried to play with QGraphicsTextItem::setTextWidth()?
Sir!

scrItem->setDocument(txtScrollEdit->document());
scrItem->setTextWidth(-1);
I am using above but it shows only the first line of QTextEdit; However, I have not inserted any enter in QTextEdit txtScrollEdit.
So, What should I do?

yagabey
5th January 2008, 14:20
Thank you jpn, i ve been looking for that..!

ashukla
6th January 2008, 11:50
Thank you jpn, i ve been looking for that..!
you can use

txtScrollEdit->setWordWrapMode (QTextOption::NoWrap); //txtScrollEdit is QTextEdit object
before the

scrItem->setDocument(txtScrollEdit->document());
scrItem->setTextWidth(-1); .
It sets the document in one line.