4

I am having a grid which inherits the QTableView with my Custom model set for view. I have also created the delegates for editing items in table cell. they all work fine (as per my requirement at least).

but my problem is , when the user click inside the cell, and if the delegate for that item is let's say QTextEdit (which can handle richtext) and user paste some text(which is copied from MSWORD with style information with text) in texteditbox. at this moment it shows text correctly(means bold,italics,font size etc) as long as the delegate is there, but after the data is set to model and view is updated, the default view does not show the style info. it shows plain HTML text (if i set model data when delegate's slot dataChanged is called and i get html from delegate).

I want tableview's default view to handle the HTML and display the text according to its style.

Anyone has any idea how to handle that? Thanks in advance! I am using QT Version 4.1.4 (i know its old, but its project demand)

maxchirag
  • 539
  • 1
  • 9
  • 18

2 Answers2

2

By default the editor displayed is associated with the type of that particular column (e.g. int, double, QDateTime). That editor is controlled by the delegate assigned to the view. In particular, take a look at its createEditor() and setEditorData() functions.

It's likely that your model is using a QString type and passes that string to the QTextEdit that automatically checks it to see if it contains HTML text and, since it does, it displays it as HTML. However, the standard delegate doesn't inspect the text.

If you want to change the view when you're not in edit mode, you need a delegate capable of displaying rich text. Here's another stack overflow answer that gives details on the delegate.

Community
  • 1
  • 1
Kaleb Pederson
  • 45,767
  • 19
  • 102
  • 147
0

The delegate uses an QTextEdit object to allow the user to edit the text, this object can handle HTML and/or richtext etc. If the view isn't showing it right it means that the delegate you're using itself can't handle that form of data. I'm afraid you will have to rewrite the virtual drawDisplay() method of your delegate in order to be able to show the data the same way QTextEdit can.

Dariusz Scharsig
  • 1,180
  • 7
  • 11