Is there any way I get current QModelIndex is Selected
-
In inside class object of QAbstractItemModel , i have a QModelIndex ,and is there any method which can tell the QModelIndex is selected in the View
-
No, the model should never know about the view. It's quite evident when you think that you can have multiple views based on the same model.
If you feel this need your design is wrong and you are doing in the model something that should be done elsewhere
-
what is correct way to get the current selection in View , if am inside QAbstractItemModel
-
@Qt-Enthusiast said in Is there any way I get current QModelIndex is Selected:
what is correct way to get the current selection in View , if am inside QAbstractItemModel
non via Qt API for the reason @VRonin mentioned.
But if you have to you need to pass a pointer to the view to the model and get it's selection model of it. Then compare the indexes.But i am curious what you are trying to achieve?
If it's about some visual representation then it should probably be handled in an custom item delegate. There you have all the info you need already. -
Any example code for that
-
http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html
Could you explain what you are trying to do?
-
@Qt-Enthusiast
I think you know how to pass a pointer to your class.
So you just need to get the selection model. And this can be very easily looked up in the docs. And when you look at the selection model docs you will know which method to use.But still you haven't told what you are trying to do.
Starting to go the wrong way here may lead to other problems in the future... -
I want to check if the ::data(index)
if the index is selected in the view (QtreeView)