PDA

View Full Version : Multiline in QAction text



skimpax
14th October 2009, 12:54
Hello,

I would like to create a QAction whose text is a multiline text.
My action is in fact used in my Recent Files handling, but not to handle a single file but a batch of files (eg. file1, file2 and file3 in my example below) and I want the user to see these files in the action text.

Something like (note the '\n' character to force new line) :


QString str;
str = "file1\nfile2\nfile3";
QAction* act = new QAction(this);
act->setText(str);


It seems not working.
Where is my error ?
(Running on Windows platform).

BR

kwisp
14th October 2009, 13:41
window use "\r\n" -- ends of lines,
but in code we use '\n'.
i think compiler rewrite '\n' on '\r\n' under windows.

but you have this problem. it`s very strange.
what textEditor and compiler are you use?

skimpax
14th October 2009, 15:09
Thanks for your interest.

I am using Visual C++ 2005 environment.

lyuts
14th October 2009, 15:58
What if you do


str = QString("file1\nfile2\nfile3");

?

I'm not sure, but the behaviour might be different from


str = "file1\nfile2\nfile3";


In the 2nd case the = operator is used because you assign str a value that it const char *. When this is done some conversions are done (see doc on QString). I think you should try to call QString explicitly.

kwisp
14th October 2009, 20:59
i get good result in all kind of code.
i think that problem with textEditor and endLine character.
may be with compiler.
try type
\r\n

skimpax
15th October 2009, 17:58
Did you try to put the text in a QAction then display this action in the menu ?

I also tried by using STL to create my string :



QAction* myAction = new QAction();
std::ostringstream ostr("");
for ( int i = 0; i < limit; ++i )
{
QFileInfo fileInfo(files[i]);
ostr << fileInfo.fileName().toStdString()<<"TT"<<std::endl;
}
filesText = QString(ostr.str().c_str());
//filesText = QString::fromStdString(ostr.str());
myAction->setText(fileText);


Still displayed in a single line.
It seems QAction Text si filtered to uniline by "removing" newlines.

Can someone confirm ?