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. How to Insert checkbox in root of Qtreeview. Treeview is created by using QDOMDocument reading XML file.
Forum Updated to NodeBB v4.3 + New Features

How to Insert checkbox in root of Qtreeview. Treeview is created by using QDOMDocument reading XML file.

Scheduled Pinned Locked Moved Unsolved General and Desktop
45 Posts 3 Posters 6.1k Views
  • 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.
  • JonBJ JonB

    @Aviral-0
    You are ignoring what I am writing. I told you how to do that, you have not acted on it.

    Aviral 0A Offline
    Aviral 0A Offline
    Aviral 0
    wrote on last edited by Aviral 0
    #41

    @JonB I have tried it bro... I tried removing !index.parent.isvalid()
    and placing some other functions.
    I am not fully understanding of what you are suggesting. can you tell me what to write there?

    Screenshot (227).png

    QVariant DomModel::data(const QModelIndex &index, int role) const
    {
        if (!index.isValid())
            return QVariant();
    
        DomItem *item = static_cast<DomItem*>(index.internalPointer());
        const QDomNode node = item->node();
    
       // if ( role == Qt::CheckStateRole && !index.parent().isValid())
        //if ( role == Qt::CheckStateRole && index.column() == 0 )
        if ( role == Qt::CheckStateRole && (index.column() == 0)  )
        {
            return static_cast< int >( item->isChecked() ? Qt::Checked : Qt::Unchecked );
    }
        if (role != Qt::DisplayRole)
            return QVariant();
    
        switch (index.column()) {
            case 0:
                return node.nodeName();
            case 1:
            {
                const QDomNamedNodeMap attributeMap = node.attributes();
                QStringList attributes;
                for (int i = 0; i < attributeMap.count(); ++i) {
                    QDomNode attribute = attributeMap.item(i);
                    attributes << attribute.nodeName() + "=\""
                                  + attribute.nodeValue() + '"';
                }
                return attributes.join(' ');
            }
            case 2:
                return node.nodeValue().split('\n').join(' ');
            default:
                break;
    
        }
    
        return item->data(index.column());
    }
    
    
    Qt::ItemFlags DomModel::flags(const QModelIndex &index) const
    {
        if (!index.isValid())
            return Qt::NoItemFlags;
    
        Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    
        if ( index.column() == 0 )
            flags |= Qt::ItemIsUserCheckable;
        return flags;
    }
    //! [6]
    
    JonBJ 1 Reply Last reply
    0
    • Aviral 0A Aviral 0

      @JonB I have tried it bro... I tried removing !index.parent.isvalid()
      and placing some other functions.
      I am not fully understanding of what you are suggesting. can you tell me what to write there?

      Screenshot (227).png

      QVariant DomModel::data(const QModelIndex &index, int role) const
      {
          if (!index.isValid())
              return QVariant();
      
          DomItem *item = static_cast<DomItem*>(index.internalPointer());
          const QDomNode node = item->node();
      
         // if ( role == Qt::CheckStateRole && !index.parent().isValid())
          //if ( role == Qt::CheckStateRole && index.column() == 0 )
          if ( role == Qt::CheckStateRole && (index.column() == 0)  )
          {
              return static_cast< int >( item->isChecked() ? Qt::Checked : Qt::Unchecked );
      }
          if (role != Qt::DisplayRole)
              return QVariant();
      
          switch (index.column()) {
              case 0:
                  return node.nodeName();
              case 1:
              {
                  const QDomNamedNodeMap attributeMap = node.attributes();
                  QStringList attributes;
                  for (int i = 0; i < attributeMap.count(); ++i) {
                      QDomNode attribute = attributeMap.item(i);
                      attributes << attribute.nodeName() + "=\""
                                    + attribute.nodeValue() + '"';
                  }
                  return attributes.join(' ');
              }
              case 2:
                  return node.nodeValue().split('\n').join(' ');
              default:
                  break;
      
          }
      
          return item->data(index.column());
      }
      
      
      Qt::ItemFlags DomModel::flags(const QModelIndex &index) const
      {
          if (!index.isValid())
              return Qt::NoItemFlags;
      
          Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
      
          if ( index.column() == 0 )
              flags |= Qt::ItemIsUserCheckable;
          return flags;
      }
      //! [6]
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #42

      @Aviral-0
      I am not your "bro"! You need to replace the original && !index.parent().isValid() with the condition for QDomNode node not having any children.

      Aviral 0A 1 Reply Last reply
      0
      • JonBJ JonB

        @Aviral-0
        I am not your "bro"! You need to replace the original && !index.parent().isValid() with the condition for QDomNode node not having any children.

        Aviral 0A Offline
        Aviral 0A Offline
        Aviral 0
        wrote on last edited by
        #43

        @JonB You don't know anything, just arrogant rude. I didn't find any solutions to my problem from you!

        jsulmJ JonBJ 2 Replies Last reply
        0
        • Aviral 0A Aviral 0

          @JonB You don't know anything, just arrogant rude. I didn't find any solutions to my problem from you!

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #44

          @Aviral-0 said in How to Insert checkbox in root of Qtreeview. Treeview is created by using QDOMDocument reading XML file.:

          I didn't find any solutions to my problem from you!

          What about "You need to replace the original && !index.parent().isValid() with the condition for QDomNode node not having any children." from @JonB - did you do that?

          Please state polite...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Aviral 0A Aviral 0

            @JonB You don't know anything, just arrogant rude. I didn't find any solutions to my problem from you!

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #45

            @Aviral-0 said in How to Insert checkbox in root of Qtreeview. Treeview is created by using QDOMDocument reading XML file.:

            @JonB You don't know anything, just arrogant rude. I didn't find any solutions to my problem from you!

            Just wow! I have made over a dozen posts so far over a week trying to help you solve your issues. Told you at each stage what to do, and at least a couple of times what to do now. Why don't you have a look back up? Thanks for nothing, bro.

            1 Reply Last reply
            1

            • Login

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