How do I access items created by a DelegateChoice inside a TableView?
-
I've spent countless hours trying to figure this out. I have an app that release print jobs for printing. Each job has a pages to print, copies to print, and cost per page. The user selects a printer and the cost in the table is updated from that calculation. If the user doesn't have enough funds to print to the printer, I want to disable the "Print" button. It seems simple enough but I've tried dozens of techniques, not of which have worked.
The simple solution seems to be to get that Button, and set its enabled value to false. However, I can't access that element by its id, so it must be out of scope.
Here is the ComboBox for printer selection: https://github.com/Libki/libki-print-station/blob/printer_selection/PrintRelease.qml#L142
Here is the Button that needs disabled: https://github.com/Libki/libki-print-station/blob/printer_selection/PrintRelease.qml#L223
Is there any way to get access to that button from the comboboxes onActivated method?
-
@Kyle-Hall if you really need to iterate over all the contentItem you can do that:
TableView{ id:tableView anchors.fill: parent Component.onCompleted:{ for(var child in tableView.contentItem.children) { console.log(tableView.contentItem.children[child].text) } } model: 50 delegate: Label{ text: modelData } }
But I would probably go with a proper c++ model and do my logic there.
-
@Kyle-Hall sure, take a look here:
https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html
the interesting section is probably the one about
QAbstractItemModel Subclass
actually, for your tableview case, there exists an actual Qt Example:
https://doc.qt.io/qt-5/qtquick-tableview-gameoflife-example.html
-
@J-Hilk thank you!
I did end up finding an alternative solution. I created a signal on my TableView and wired it to each button. Then, when the ComboBox changes, I call a function on the TableView that fires the signal, triggering the print buttons to reevaluate if they should be enabled or not.