PDA

View Full Version : QtextEdit add to each line strings



Dariusz
1st October 2013, 21:31
Heya

This is silly but I cant break it.

I have text in textEdit

testa
testb
testc

I want it to look like this

testa;testb;testc;

I got as far as getting it all in 1 line but I cant figure out how to add ; :/


fromQT = self.qe.toPlainText()
toPlain=str(fromQT)
prefix = ''.join((';',toPlain))
mystr = ''.join([line.strip() for line in prefix])

Thanks in advice.

toufic.dbouk
1st October 2013, 22:33
Hello,

but I cant figure out how to add
If you mean you just wanna add the text , you can add it either by passing it through the constructor when creating the text edit or by using setText method.

QString myStr;
QTextEdit *txtedit = new QTextEdit(myStr);
txtedit->setText(myStr);
Take a look at other functions of QTextEdit too QTextEdit (http://qt-project.org/doc/qt-5.0/qtwidgets/qtextedit.html).
Im sure you can find another way to concatenate the strings the way you want.

Dariusz
2nd October 2013, 00:08
Heya

bummer I forgot to mention its python ! :) Sorry

In any case the answer for my pain was


myStr.replace('/n',';')

Thanks for help !: )