Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Qt] QStandardItemModel and checkbox
Forum Updated to NodeBB v4.3 + New Features

[Qt] QStandardItemModel and checkbox

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tom01ms41
    wrote on last edited by
    #1

    Hi all:

    I have a custom model derived from QStandardItemModel and set setCheckable(true) for each QStandardItem. the view is QTreeView.

    I want to do is whenever I click on node's checkbox, the checkState will flip between check/uncheck. other nodes(parent especially) will be Check/Uncheck/PartiallyChecked.

    tristate enabled also
    @
    Qt::ItemFlags FileSystemModel::flags(const QModelIndex & index) const
    {
    return QStandardItemModel::flags(index) | Qt::ItemIsTristate;
    }
    @

    I've try to modify value in QStandardItemModel::setData
    @
    bool FileSystemModel::setData(const QModelIndex& index, const QVariant& value, int role)
    {
    QVariant new_value=value;

    if (role==Qt::CheckStateRole) {
        auto check = static_cast<Qt::CheckState> (value.toUInt());
        if (check==Qt::PartiallyChecked)
            new_value = Qt::Unchecked;
    }
    return QStandardItemModel::setData(index,new_value,role);
    

    }
    @

    but it not work.
    any ideas?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved