I would like to add a custom role to a QFileSystemModel (probably to a derived model). I want to use this role to save the check state of a CheckBox which is displayed next to the filename in a custom delegate. How can this be done?
相关问题
- Sorting 3 numbers without branching [closed]
- QML: Cannot read property 'xxx' of undefin
- QML: Cannot read property 'xxx' of undefin
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
相关文章
- ubuntu20.4中c#通过c++库调用python脚本
- Qt槽函数自动执行多遍
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
I have used using the example Qt Quick Controls - File System Browser Example removing the part of the selection.
The steps were the following:
Add a new role in
roleNames
:Create a container that stores the information of the selection, in this case I will use
QMap
:Overwrite the
data()
method that returns the state if it is stored in the container, if it is not returnedQt::UnChecked
as the default value:Overwrite the
setData()
method, which you must modify if necessary and create the data.I have added a new column where I have established the delegate to the
CheckBox
and I used theonCheckedChanged
slot to set the value using thesetData()
method, theQModelIndex
is passed, the data and the role, in this case, pass 10 because it is the value number ofQt::CheckStateRole
.The complete example can be found in the following link.