3

I want to use QListWidget to display my content. But some of the content is quite long and I want to make the text continue on a second row instead of showing a horizontal scrollbar.

I use Qt Creator and I can't seem to find any options in the design view.

4
  • You should use Model-View-Delegate instead of QListWidget Commented Jan 2, 2014 at 17:16
  • for second row you mean another line or another cell? Commented Jan 2, 2014 at 17:33
  • @jalone: what cell do you mean? Isn't that a table concept, and it is not QTableWidget? :) I think the OP just wishes to have line break rather than a new row so that if one gets the data, the whole text would be obtained, but I am just guessing here. :) Commented Jan 2, 2014 at 21:05
  • @LaszloPapp: yes sorry i meant QListWidgetItem not cell. Commented Jan 2, 2014 at 21:21

1 Answer 1

5

Enable word wrapping by calling

void setWordWrap ( bool on ) 

and set text elide mode to Qt::ElideNone

void setTextElideMode ( Qt::TextElideMode mode ) 

Also you may check that you didn't set too small maximum height for your items in the list.

P.S. Because you wrote about horizontal scrollbar, you definitely want to have multiline text in item, but not the item on multiple rows.

Sign up to request clarification or add additional context in comments.

2 Comments

If the list item is one long sequence of characters that does not contain word boundaries, the above does not work, i.e. the string does not wrap.
You might need to use something like QTextOption::WrapAnywhere flag, if your widget supports it ... or something similar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.