Results 1 to 4 of 4

Thread: QListWidgetItem text too long

  1. #1
    Join Date
    Jan 2006
    Posts
    73
    Thanks
    16
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QListWidgetItem text too long

    Hello,

    I have a widget "events_widget" that takes the whole screen
    and I do something like

    Qt Code:
    1. QStringList tokens;
    2. ...
    3. QString text = tokens.at(1) + "\n"
    4. + " " + tokens.at(2) + "\n"
    5. + " Cap: " + tokens.at(3) + " Reg: " + tokens.at(4);
    6. + " Can: " + tokens.at(5) + " Wait: " + tokens.at(6);
    7. QListWidgetItem* item = new QListWidgetItem(text,events_widget);
    To copy to clipboard, switch view to plain text mode 

    The problem is that when tokens.at(1) is too long for the screen, the remaining of the the text does not appear. Since I am targeting a Symbian ^3, the end of the screen is reached quite fast.
    Any idea, on how to fix that?

    thank you!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListWidgetItem text too long

    If you would use a custom delegate you can use Qt::TextWordWrap, but with a QListWidget you have to set setWordWrap() to true. That should do the trick.

  3. The following user says thank you to Lykurg for this useful post:

    jcr (18th October 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidgetItem text too long

    For performance reasons I suggest to change your code to either of the following:

    Qt Code:
    1. QString text = QString("%1\n %2\b Cap: %3 Reg: %4 Can: %5 Wait: %6")
    2. .arg(tokens.at(1)).arg(tokens.at(2)).arg(tokens.at(3)).arg(tokens.at(4)).arg(tokens.at(5)).arg(tokens.at(6));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QString text = tokens.at(1) % "\n"
    2. % " " % tokens.at(2) % "\n"
    3. % " Cap: " % tokens.at(3) % " Reg: " % tokens.at(4);
    4. % " Can: " % tokens.at(5) % " Wait: " % tokens.at(6);
    To copy to clipboard, switch view to plain text mode 

    For maintainance reasons I suggest to use a custom delegate with custom roles instead of using such strange constructions as what you are currently doing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    jcr (20th October 2010)

  6. #4
    Join Date
    Jan 2006
    Posts
    73
    Thanks
    16
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidgetItem text too long

    You are 100% right; with custom delegates, it is much cleaner and one can do more things as well.

Similar Threads

  1. QCheckBox with long text label
    By Ferdous in forum Newbie
    Replies: 5
    Last Post: 29th October 2011, 19:05
  2. draw long text in rect
    By yxtx1984 in forum Qt Programming
    Replies: 1
    Last Post: 21st January 2010, 09:00
  3. buton text long ?
    By electronicboy in forum General Programming
    Replies: 3
    Last Post: 2nd November 2009, 10:21
  4. Layout long text in QTableWidget
    By Tamtam in forum Newbie
    Replies: 0
    Last Post: 13th February 2009, 15:09
  5. How to trim long text in status bar
    By araglin in forum Newbie
    Replies: 2
    Last Post: 15th January 2009, 21:36

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.