PDA

View Full Version : QListWidgetItem text too long



jcr
18th October 2010, 18:29
Hello,

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



QStringList tokens;
...
QString text = tokens.at(1) + "\n"
+ " " + tokens.at(2) + "\n"
+ " Cap: " + tokens.at(3) + " Reg: " + tokens.at(4);
+ " Can: " + tokens.at(5) + " Wait: " + tokens.at(6);
QListWidgetItem* item = new QListWidgetItem(text,events_widget);


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!

Lykurg
18th October 2010, 21:38
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.

wysota
18th October 2010, 23:17
For performance reasons I suggest to change your code to either of the following:


QString text = QString("%1\n %2\b Cap: %3 Reg: %4 Can: %5 Wait: %6")
.arg(tokens.at(1)).arg(tokens.at(2)).arg(tokens.at (3)).arg(tokens.at(4)).arg(tokens.at(5)).arg(token s.at(6));


QString text = tokens.at(1) % "\n"
% " " % tokens.at(2) % "\n"
% " Cap: " % tokens.at(3) % " Reg: " % tokens.at(4);
% " Can: " % tokens.at(5) % " Wait: " % tokens.at(6);

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.

jcr
20th October 2010, 00:19
You are 100% right; with custom delegates, it is much cleaner and one can do more things as well.