[Interest] QColumnView and QTreeView using same model

Michael Jackson mike.jackson at bluequartz.net
Wed May 4 21:07:10 CEST 2022

Thank you for the tips. Got the checkboxes working. 
Mike Jackson

On 5/4/22, 10:06 AM, "Interest on behalf of Tony Rietwyk" <interest-bounces at qt-project.org on behalf of tony at rightsoft.com.au> wrote:

    On 4/05/2022 11:43 pm, Michael Jackson wrote:
    > ...
    > Now on to figure out how to display checkboxes next to each item. I've tried:
    > Qt::ItemFlags ImportDataStructureModel::flags(const QModelIndex& index) const
    > {
    >    if(!index.isValid())
    >    {
    >      return {};
    >    }
    >    return Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | QAbstractItemModel::flags(index);
    > }
    > Which does not seem to show anything. I'll probably have to create a custom delegate.
    > --
    > Mike Jackson
    Hi Mike,

    If you return flag ItemIsUserCheckable in your model, then you must also 
    return a valid variant with Qt::CheckState for data(Qt::CheckStateRole) 
    - it won't just assume Qt::Unchecked.

    Ditto with the item widgets - besides item->setFlags, you need to call 
    item->setCheckState as well.


    Interest mailing list
    Interest at qt-project.org

More information about the Interest mailing list