zoukankan      html  css  js  c++  java
  • qt tableview使用

        Qt::CheckState checkSibling(QStandardItem * item);
        void treeItem_checkAllChild(QStandardItem * item,bool check = true);
        void treeItem_checkAllChild_recursion(QStandardItem * item,bool check = true);
        void treeitemCheckchildchanged (QStandardItem * item );
        void treeItemChanged(QStandardItem * item);




    void ConfigurationFrame::treeItemChanged(QStandardItem * item)
    {
    if(item == nullptr)
    return;
    if(item->isCheckable())
    {
    //如果条目是存在复选框的,那么就进行下面的操作
    Qt::CheckState state = item->checkState();//获取当前的选择状态
    if(item->isAutoTristate())
    {
    //如果条目是三态的,说明可以对子目录进行全选和全不选的设置
    if(state != Qt::PartiallyChecked)
    {
    //当前是选中状态,需要对其子项目进行全选
    treeItem_checkAllChild(item,state == Qt::Checked ? true : false);
    }
    }
    else
    {
    //说明是两态的,两态会对父级的三态有影响
    //判断兄弟节点的情况
    treeitemCheckchildchanged(item);
    if(state == Qt::Checked)
    {
    selectedFactorList.append(item->text());
    }
    else
    {
    selectedFactorList.removeOne(item->text());
    }
    }
    }
    }
    void ConfigurationFrame::treeItem_checkAllChild(QStandardItem *item, bool check)
    {
    if(item == nullptr)
    return;
    int rowCount = item->rowCount();
    for(int i=0;i<rowCount;++i)
    {
    QStandardItem* childItems = item->child(i);
    treeItem_checkAllChild_recursion(childItems,check);
    }
    if(item->isCheckable())
    {
    item->setCheckState(check ? Qt::Checked : Qt::Unchecked);
    }
    }

    void ConfigurationFrame::treeItem_checkAllChild_recursion(QStandardItem *item, bool check)
    {
    if(item == nullptr)
    return;
    int rowCount = item->rowCount();
    for(int i=0;i<rowCount;++i)
    {
    QStandardItem* childItems = item->child(i);
    treeItem_checkAllChild_recursion(childItems,check);
    }
    if(item->isCheckable())
    {
    item->setCheckState(check ? Qt::Checked : Qt::Unchecked);
    }
    }
    void ConfigurationFrame::treeitemCheckchildchanged(QStandardItem *item)
    {
    if(nullptr == item)
    return;
    Qt::CheckState siblingState = checkSibling(item);
    QStandardItem * parentItem = item->parent();
    if(nullptr == parentItem)
    return;
    if(Qt::PartiallyChecked == siblingState)
    {
    if(parentItem->isCheckable() && parentItem->isTristate())
    parentItem->setCheckState(Qt::PartiallyChecked);
    }
    else if(Qt::Checked == siblingState)
    {
    if(parentItem->isCheckable())
    parentItem->setCheckState(Qt::Checked);
    }
    else
    {
    if(parentItem->isCheckable())
    parentItem->setCheckState(Qt::Unchecked);
    }
    treeitemCheckchildchanged(parentItem);
    }
    Qt::CheckState ConfigurationFrame::checkSibling(QStandardItem *item)
    {
    //先通过父节点获取兄弟节点
    QStandardItem * parent = item->parent();
    if(nullptr == parent)
    return item->checkState();
    int brotherCount = parent->rowCount();
    int checkedCount(0),unCheckedCount(0);
    Qt::CheckState state;
    for(int i=0;i<brotherCount;++i)
    {
    QStandardItem* siblingItem = parent->child(i);
    state = siblingItem->checkState();
    if(Qt::PartiallyChecked == state)
    return Qt::PartiallyChecked;
    else if(Qt::Unchecked == state)
    ++unCheckedCount;
    else
    ++checkedCount;
    if(checkedCount>0 && unCheckedCount>0)
    return Qt::PartiallyChecked;
    }
    if(unCheckedCount>0)
    return Qt::Unchecked;
    return Qt::Checked;
    }

  • 相关阅读:
    修改mysql root用户密码(忘记密码)
    激活IDEA 2019.1
    数据库事务的4大特性与隔离级别
    使用HttpClient调用第三方接口
    SpringBoot使用logback自定义配置时遇到的坑 --- 在 /tmp目录下自动生成spring.log文件
    更新数据库中数据时出现: Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences 问题
    数值return ++ 的坑
    string整合Quartz定时器
    idea配置自动编译项目配置
    CASE WHEN 及 SELECT CASE WHEN的用法
  • 原文地址:https://www.cnblogs.com/tianmochou/p/11063297.html
Copyright © 2011-2022 走看看