QML force delegate instantiation - qt

I have a ListView inside Scrollview and a delegate which instantiates items of ListView.
After model change I want to force instantiation of delegates for all items in the model. I use cacheBuffer, so instantiated items won't gone.
So the question is how can I achieve that?

Related

Does the ListView redraw the underlaying model if the model changes?

The question is basically the title, but some more detail:
I have subclassed the QAbstractListModel, lets name it myModel.
I am creating the content of myModel in c++ code, then feeding it into a ListView in QML.
My code modifies myModel in C++ code and I can see the modifications right away in my ListView, which is fine.
My question is, that does the ListView redraws all of its elements, when the underlaying model changes (like adding an item) or just draws the new item?
That depends upon what signals you model emits, some of which may not be obvious if you just override some protected methods. See the documentation of the signals in the QAbstractItemModel Class.
Under the ListView delegate I have checked how many times does Component.onCompleted and Component.onDestruction called. The results are, that when a new item is inserted the Component.onCompleted is called only once and when an item is removed the Component.onDestruction is called only once, which means that ListView doesn't redraw the whole list when inserting and removing items!

QML: update item of QSortFilterProxyModel when source item changed

I have model derived from QAbstractListModel and it's a source of filter proxy derived from QSortFilterProxyModel. Filter proxy used as model in TableView at QML.
So, if something changes in initial model, proxy automatically resortes and updates all delegated (even if delegate doesn't need update). So, I disable property dynamicSortFilter of proxy. Now, delegates not update even if needed. So, I can make connection to model and detect signal dataChanged inside delegate. But how to update this delegate after this?

Add child to parent component that is not visible in flex

I have a mxml file that extends a parent class. The parent has a component that is hidden initially and only shown once a button is pressed. I would like to add a new child component to this hidden component from my extended mxml. Is there a way to access the super component and add the child once the buton is pressed? Maybe listen to an event?
Right now i have a solution that solves the problem by loading the hidden components but it´s not a nice solution.
super.advancedOptionsSearchBox.getChildren();
super.advancedOptionsSearchBox.addChildAt(getEANContainer(), 1);
If i do not call the getChildren I get a index out of bounds exception on the call to addChildAt method since the array of children is empty in the hidden component.
Couldn't you just set property
creationPolicy="all"
to your component? That way it's created even if it's initially not visible.

Qt: Custom QListView and live controls

My custom QListView has delegates to paint the items. I'd like to add a live control to some of the row items (like a QLineEdit), that'll always be present in the row and will automatically scroll correctly with the list.
Since items are not widgets, I cannot assign a control to be a child of an "item", thus scrolling will leave the control in its fixed spot within the QListView widget.
Is there another way?
Is that even possible?
Normally the edit widget is created (and positioned) by the delegate when an QEvent::EnterEditFocus event occurs then destroyed when a subsequent QEvent::LeaveEditFocus occurs and the data is sent back to the model. The delegate should then repaint with the new model data.
Could you expand on what you mean by a "live" control?
Why would you want to have an edit widget constantly open? I think a better way to do this would be to create a delegate which paints the normal view (i.e. for Qt::DisplayRole) in a way which you want. Assuming you create your subclass view correctly, the delegate should still update when the model changes.
If you really want to do what you're asking though, I suspect you might be able to by:
creating your own item delegate (subclassing QAbstractItemDelegate)
reimplement createEditor() to use a QLineEdit
then use the delegate's updateEditorGeometry()
Have a read of the Delegate Classes section of the Introduction to Model/View Programming though first. The Spin Box Delegate Example and Pixelator Example are worth studying too if you haven't already.

destroy open item editor or item renderer in flex

Is it possible to destroy/close open item editor or item renderer of a datagrid in different mxml page?
I heard about the functions editedItemRenderer and destroyItemEditor on Datagrid. Can I use these functions in different mxml page?
Your question is a bit confusing.
Flex Applications do not have the concept of a page in the same way that HTML does. You probably mean different views, or MXML Components.
All itemEditors are created and destroyed as needed. If you are not viewing the itemEditor on screen, then likely something else has focus and the itemEditor was destroyed automatically.
In most cases, two components should not talk to each other using anything other than their defined API. so, you can have one component dispatch an event, then it's parent listen for the event and have that parent call methods on another component [such as a DataGrid].

Resources