Page 1 of 1

Access the value of a TreeView Checkbox

Posted: Wednesday 12th May 2021 8:21am
by bazzvn
I am running Gambas 3.15.2 under Debian Testing with the Plasma 5.20 desktop and I see that it is possible to show a checkbox for each item in a qt4/qt5 TreeView control. I would like to be able to iterate through the items in the TreeView and find those that have been marked with a check. I know how to iterate through the items in a TreeView, but I can't seem to find any documentation on how to return which items have been checked. I would be grateful for any help.
bazzvn

Re: Access the value of a TreeView Checkbox

Posted: Wednesday 12th May 2021 3:32pm
by cogier
....I see that it is possible to show a checkbox for each item in a qt4/qt5 TreeView control....
Can you post some code showing how you do this.

Re: Access the value of a TreeView Checkbox

Posted: Wednesday 12th May 2021 9:33pm
by Quincunxian
In the treeview control, select ShowCheck in the parameter list.
This enables a single select only radio button next to each treeview item.

If you then set the mode parameter to multiple, the radiobutton changes to a checkbox and and you can select multiple items in any child node.

The Selection parameter of the treeview maintains a string array of the keys of the selected items.

To get a count of these is
My_Label.Text = Str(My_Treeview.Selection.Count)
If  (My_Treeview.Selection.Count > 0) Then 'some item has been selected.

Re: Access the value of a TreeView Checkbox

Posted: Thursday 13th May 2021 9:26am
by bazzvn
Thanks Quin, that partly answers my question, but I'm not sure whether it will serve my purpose. Basically, I have a large collection of documents that are catalogued in an sqlite database. The idea is to assign tags and attributes to them so that they can be found quickly and cross referenced. I presently use the Current.Picture property to do it and it seems to work quite well (see attached example). I think I will stick with my current way for the present until I have more time to explore the ShowCheck property in Qt4/Qt5 TreeViews.

Cogier, I can't provide more information on the ShowCheck property than has already been provided by Quin, but any suggestions for a better way to do it than in my example would be welcome.

Re: Access the value of a TreeView Checkbox

Posted: Thursday 13th May 2021 2:32pm
by cogier
I could not see an easier way to do this. However, I have made a few changes that you may (or may not) like which include: -
  • The Form is now expandable
  • The list is now updated by a Timer, so you don't have to leave the TreeView to update
  • Added a simple NewItem Form, the Timer sorts the rest
  • aTemp now loaded in one line
I hope it helps.
TreeViewCheck_CO-0.0.1.tar.gz
(15.81 KiB) Downloaded 226 times

Re: Access the value of a TreeView Checkbox

Posted: Friday 14th May 2021 2:10am
by bazzvn
Thanks Cogier for taking the time to check the code. Your modifications result in more elegant code. I've never really understood how to use timers properly, so your addition of a timer was also instructive. The example project is just a subset of the code in my real FTags form, which includes additional code to create new tags and sub-tags, and for saving them to relevant tables in an sqlite database. Since it seems to work well, I use a similar approach for selecting tags to filter my database records (again inspired by the approach used in apps like Digikam and XnViewMP).

Thanks again.

Best wishes to all,
bazzvn