Dear visitor, welcome to QtForum.org.
If this is your first visit here, please read the Help. It explains in detail how this page works.
To use all features of this page, you should consider registering.
Please use the registration form, to register here or read more information about the registration process.
If you are already registered, please login here.

Rich Text in a table. Help!

In a table, I am trying to a create rows that can support multiple lines and different text formating in a single table item. Below is a attached screenshot of what I am trying to achieve.

Can anyone suggest a way to do this in Qt 4? It does not necessarily be a table, as long as it can support multiple columns. For example, I have looked at tableview, treeview, tablewidget and treewidget.

There are multiple ways to do it. One of them is using a simple model and a QTreeView or QTableView with a custom delegate. I guess you can also use QTreeWidget or QTableWidget. Using QTextDocument is a way too, rendering the text on a widget directly can also be an option... As I said, you can do it in many ways

As wysota said there is more than one way. As a general rule there is always more than one way to skin a cat as the saying goes. Try reading the Qt documentation. You might be suprised with what you come up with.

There is an old saying. Give a man a fish you feed him for a day teach him to fish and you feed him for a lifetime.

The Qt Documentation is your friend, and is really easy to understand as well.

Visit http://www.qtcentre.org where the owners care about the future of the forums.

But it crashes on the first call to createLine, and I don't know why. Notice that I took the example code from the class docs of QTextLayout, and that one contained an invalid reference to the non-existing QTextLine::layout() method. I corrected that one to setLineWidth(), but the execution does not reach that point anyway.

Hi,
Just noticing you that Trolltech confirmed both the documentation bug in QTextLayout, and the crash while calling QTextLayout::createLine() from a QItemDelegate subclass. After this it is quite a question what "many ways" are left to go if I want rich text in itemview cells?
1) Subclassing QItemDelegate was the only realistic way, but crashes during laying out the text.
2) QTextDocument can not render text, so I don't really see how does that qualify as an independent alternative. You will rather need to use QTextDocument as part of an other alternative.
3) Own custom widget. Seems quite far fetched to reimplement most of what QItemView does (scrolling, dragging, cell resizing, selection modes, editors, etc) just to replace the cell plain text with fancy text.
4) QTextEdit or QTextBrowser does not provide many itemview features (scrolling, dragging, cell resizing, selection modes, editors, etc)
5) Sorry but the only way I found to remain is opening persistent editors on all fields, and display each cell in a separate widget. Some of the many drawbacks: cursor movement will only move within the current cell, selected fields will not look different, and drag-selection will only select within a single cell, even if you drag throught multiple cells.
6) AFAIK Qt 4.1 will offer a feature to directly place widgets in itemview cells, but the same drawbacks remain as in #5.

If you are interested here is the minimal dummy example which can reproduce the mentioned crash.