How to show hypertext in default view of QTableView?

I have a grid that inherits a QTableView with my custom view model. I also created delegates to edit items in a table cell. they all work fine (at least as per my requirement).

but my problem is when the user clicks inside the cell, and if the delegate is asked to say QTextEdit (which can handle richtext) for this element, and the user inserts some text (which is copied from MSWORD with style information with text) in the text box. at the moment it shows the text correctly (means bold, italics, font size, etc.) as long as the delegate exists, but after updating the data for the model and viewing the updated view does not display style information. it shows plain HTML text (if I install model data when the dataChanged delegate slot is called and I get html from the delegate).

I want the default view of tableview to process HTML and display text according to my style.

Does anyone know how to handle this? Thank you in advance! I am using QT Version 4.1.4 (I know its old, but its project requires)

+4
source share
2 answers

By default, the displayed editor is associated with the type of this particular column (for example, int, double, QDateTime). This editor is managed by the delegate designated for submission. In particular, look at createEditor () and setEditorData () .

Your model probably uses the QString type and passes this string to a QTextEdit, which automatically checks it if it contains HTML text, and since it does, it displays it as HTML. However, the standard delegate does not validate the text.

If you want to change the view when you are not in edit mode, you need a delegate that can display rich text. Here is another answer that provides details about the delegate .

+2
source

The delegate uses the QTextEdit object to allow the user to edit the text, this object can process HTML and / or richtext, etc. If the view does not show it correctly, it means that the delegate that you use yourself cannot process this data form. I'm afraid you will have to rewrite your delegate's virtual drawDisplay() method so that it can display data in the same way as QTextEdit .

0
source

All Articles