voidMyProgressBar::p aint (qpainter* painter,Constqstyleoptionviewitem& option,Constqmodelindex& index)Const{ //--------------------fetch data, test data--------------------------------- ConstQabstractitemmodel *item_model = Index.model ();//get the model based on the current index (including countless information) intNrow = Index.row ();//Current line (the current line each time)//Note that this index.model is a function of the QT library itself:http://doc.qt.io/qt-4.8/qmodelindex.html //Of course it can only return a qabstractitemmodel pointer, not the model that I inherited and modified, so it can't get the extra information I added//At this point, you have to drop the model to subclass to get exactly the information you need, about 5 ways//either use dynamic_cast, do rtti, either force the conversion (equivalent to static_cast), or record in advance the type pointers of my newly defined model in MyProgressBar, and don't know if Qt has any extra methods//The root cause of this problem is that the class library is not written by itself, it provides functions that can only get the parent class pointer}
First-hand experience: a situation where sub-class details need to be obtained (five methods)