updating model columns based on view update
-
@user4592357 said in updating model columns based on view update:
this list in model is not changed, i.e. columnCount() still returns the old 5.
That's absolutely correct - you only hide a column in the view, you don't change the model. Why should the model change it's columnCount at all?
-
@user4592357 said in updating model columns based on view update:
this list in model is not changed, i.e. columnCount() still returns the old 5.
That's absolutely correct - you only hide a column in the view, you don't change the model. Why should the model change it's columnCount at all?
@Christian-Ehrlicher said in updating model columns based on view update:
Why should the model change it's columnCount at all?
the problem is that, since model column count is the same,
data()is called for those hidden columns. -
@Christian-Ehrlicher said in updating model columns based on view update:
Why should the model change it's columnCount at all?
the problem is that, since model column count is the same,
data()is called for those hidden columns.@user4592357 Why is this a problem?
-
@user4592357 Why is this a problem?
@Christian-Ehrlicher
i have one column, which does some heavy calculation for data retrieval, so i wouldn't want extra work be done -
@Christian-Ehrlicher
i have one column, which does some heavy calculation for data retrieval, so i wouldn't want extra work be done@user4592357 You should not do the calculation inside the data() function.
-
@user4592357 You should not do the calculation inside the data() function.
@Christian-Ehrlicher
then where? ifdata()wants to retrieve that model index info, i need to provide the correct data, since i don't know whether column is hidden in gui or not -
@user4592357 said in updating model columns based on view update:
then where?
When you fill the data into the model for example. data() is called very often and should do as less work as possible.
-
@Christian-Ehrlicher
then where? ifdata()wants to retrieve that model index info, i need to provide the correct data, since i don't know whether column is hidden in gui or not@user4592357
In view of @Christian-Ehrlicher's comments, you might consider adding aQProxyModelwhich hides the computed column from the outside world, makes life simpler. -
@Christian-Ehrlicher
okay, now i add the value of that column in a method filling tree node, only if the column is to be shown, because the computation of that data is slow.
now, if the column is hidden, and i show it, it doesn't display the data (because the logic of filling the node was done somewhere else) -
@Christian-Ehrlicher
okay, now i add the value of that column in a method filling tree node, only if the column is to be shown, because the computation of that data is slow.
now, if the column is hidden, and i show it, it doesn't display the data (because the logic of filling the node was done somewhere else)@user4592357
I don't understand. If you allow for allow for hidden columns becoming shown, you have to write the logic to ensure the data is available. If necessary, react to the column being hidden/shown by refreshing the model or changing it or whatever is required to fetch the necessary data.