Results 1 to 6 of 6

Thread: Multiline in QAction text

  1. #1
    Join Date
    Jul 2009
    Location
    France
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Multiline in QAction text

    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) :
    Qt Code:
    1. QString str;
    2. str = "file1\nfile2\nfile3";
    3. QAction* act = new QAction(this);
    4. act->setText(str);
    To copy to clipboard, switch view to plain text mode 

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

    BR

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiline in QAction text

    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?
    east or west home is best

  3. #3
    Join Date
    Jul 2009
    Location
    France
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiline in QAction text

    Thanks for your interest.

    I am using Visual C++ 2005 environment.

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Multiline in QAction text

    What if you do
    Qt Code:
    1. str = QString("file1\nfile2\nfile3");
    To copy to clipboard, switch view to plain text mode 
    ?

    I'm not sure, but the behaviour might be different from
    Qt Code:
    1. str = "file1\nfile2\nfile3";
    To copy to clipboard, switch view to plain text mode 

    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.
    I'm a rebel in the S.D.G.

  5. #5
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiline in QAction text

    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
    east or west home is best

  6. #6
    Join Date
    Jul 2009
    Location
    France
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiline in QAction text

    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 :

    Qt Code:
    1. QAction* myAction = new QAction();
    2. std::ostringstream ostr("");
    3. for ( int i = 0; i < limit; ++i )
    4. {
    5. QFileInfo fileInfo(files[i]);
    6. ostr << fileInfo.fileName().toStdString()<<"TT"<<std::endl;
    7. }
    8. filesText = QString(ostr.str().c_str());
    9. //filesText = QString::fromStdString(ostr.str());
    10. myAction->setText(fileText);
    To copy to clipboard, switch view to plain text mode 

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

    Can someone confirm ?

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. QAction text color (QMenu)
    By StefanK in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2009, 16:14
  3. Match the text beetween two string
    By dreamer in forum Qt Programming
    Replies: 4
    Last Post: 20th May 2008, 15:48
  4. getting QAction text from the slot
    By roxton in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2008, 14:03
  5. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 16:30

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.