Search code examples
c++qtqt-creatorword-wrap

Qt c++ Wrap text (richtext) in tableview


I use QItemDelegate and QStandardItemModel to display text and images in a QTableView (text and images are stored as richText in my database).

The problem is, that the text does not wrap, when i use QItemDelegate. If i do not use QItemDelegate the text does wrap but images are not displayed.

My Question: How can i make text-wrapping when using ItemDelegate?


Solution

  • It works with Qt::TextWrapAnywhere flag in DrawText method.

    painter->drawText(xText, yText, wText, hText, 
                      Qt::TextWrapAnywhere | Qt::AlignCenter, QString("  ")
                 .append(m_RowsWithIconAndText.value(index.row())));