How to display a model data in 2 views in different format, say in binary and hexadecimal?
-
Hi I'm new to both GUI programming and Qt, just having a question and it has confused me for days.
I need to display a model in 2 views, but in different format, in details, I have a 2 dimensional array of unsigned char, and want to display them in 2 table, one in binary format, and the other in hexadecimal.
The model is derived from the QAbstractTableModel, and I'm using 2 QTableView to display it.
I know I can let the model to output a QString in binary or hexadecimal format but that doesn't meet my requirement to share the same model within 2 views. So I just let the data() function to return a unsigned char directly.
I guess a delegate is the right way to get the data rendered properly for each view? but I couldn't find a document about this, the delegate documents are all about editing data with widgets or graphic displays.
I noticed there is a function called displayText() in QStyledItemDelegate, and I tried it and it works (derived 2 new delegates from it and overrided the displayText() functions) . But this function doesn't exist in QItemDelegate, according to the class reference, QStyledItemDelegate only comes to existance after Qt 4.4, so I guess there must be some other way to do it, in other words I might use the wrong approach.
Could anyone give me some advice on this? Thanks
-
Well you can create two proxy models, one for hex and one for bin. "qabstractproxymodel":http://qt-project.org/doc/qt-4.8/qabstractproxymodel.html
"example":http://qt-project.org/doc/qt-5.0/qtwidgets/itemviews-customsortfiltermodel.html - this is a simple example for creating custom proxy model. In your case you need reimplement data(). -
Hi,
You can also manage to do it with only one delegate that you would configure. What version of Qt are you using ?
-