View Full Version : Is there any way to convert a QWebView object to a QVariant object?

22nd January 2014, 18:01
First of all, sorry I don't have much sample code to go off of, I'm really lost on this. I'm working in Qt 4.7, and I have a UI with a TableView object. I have the data() function set up so that everything else on the table populates correctly. However, there is one cell that is giving me lots of problems. Some of the cells need to be populated with data from an html page. Most of this is fine, as I just have data() return QVariant(dataneeded.toPlainText()) for those portions. However, one part is in tags, and in the original HTML page creates a button. My project manager wants this code to create a button on the table. However, when I try to copy the code over like the others (which just require text from the webpage) it just copies the text of the html, e.g. .

Now, as I was testing this, I had a different UI set up with a QWebView to see the results I was getting from this webpage. When I passed the same portion of the HTML into the QWebView object, it created the button, just like on the original webpage. I figured, if I could create a QWebView object, create the button within that, and return that to the proper index on the TableView object with the data() function, it would work. However, the data() function needs to return a QVariant, and I can't find any way to format it to get the QWebView through. My question is, does anyone know any way to format the result of the QWebView object to pass it as a QVariant for the data() function? Also if anyone knows any other ways that would create the button that would be great to, I'm just at a total loss. Thanks!

22nd January 2014, 21:22
Some options
Have data() return the HTML not the plain text. Then in the view use a delegate to paint the HTML using Webkit.
Have data() return a pixmap obtained by rendering the HTML with Webkit and a delegate to display the image.