Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6820229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:24:00+00:00 2026-05-26T21:24:00+00:00

I have a QTreeView to which I set a subclassed DomModel:QAbstractItemModel. Each item is

  • 0

I have a QTreeView to which I set a subclassed DomModel:QAbstractItemModel. Each item is a DomItem which deals mostly with QDomNode. I set QDomDocument to this model. I think I’ve derived this system from one of the Qt examples.

It has 3 columns: 0 for node name, 1 for attributes and 2 for value.

Anyway, I wanted to make this XML DOM tree editable. I’ve modified some flags such as Qt::ItemIsEditable and some other things in the model class and now I can edit the model through QTreeView by double clicking.

For column 2 it’s easy, since QDomItem has this setNodeValue function, however I’ve found there are no “set” functions for item->node().NodeName() and item->node().attributes() which would, I presume, modify columns 0 and 1.

So now when I modify column 2 it works, however columns 0 and 1 revert to their previous values upon pressing enter.

bool DomModel::setData(const QModelIndex &index, const QVariant &value,
                    int role)
{
if (role != Qt::EditRole) return false;

DomItem *item = static_cast<DomItem*>(index.internalPointer());

switch (index.column()){
    case 0:
        // ???
        break;
    case 1:
        // ???
        break;
    case 2:
        item->node().setNodeValue(value.toString());   // This works - QTreeView is updated
        break;
}
...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:24:01+00:00Added an answer on May 26, 2026 at 9:24 pm

    Well, apparently item->node().toElement() which returns a QDomElement has the necessary “set” functions and it works. So I think I’ve found a way to fully modify my XML DOM file through QTreeView.

    This does the trick for me:

    switch (index.column()){
       case 0: // added
          item->node().toElement().setTagName(value.toString());
          break;
       case 1: // added
          // this shall be modified to account for nonstandard spacings, etc.
          aux = value.toString().trimmed();
          aux.remove("\"");
          attributes.clear();
          attributes = aux.split(" ");
          for(int i = 0; i<attributes.size(); i++){
             item->node().toElement().setAttribute(attributes.at(i).split("=").at(0),
                                                   attributes.at(i).split("=").at(1));
          }
          break;
       case 2: // Left it as it is
          item->node().setNodeValue(value.toString());   // This works - QTreeView is updated
          break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a treeview (winforms) which have different item types on it. I have
I have GUI application with gtk.Treeview component. It's model is set to gtk.Treestore, which
I have a treeview in which i need to set the font of only
I have a child form which has a find form in it. I set
I have a window which contains a QTreeView ( databaseTreeView ) on a subclass
I have a QTreeView which has the ExtendedSelection attribute (users may select more than
I have a TreeView in my form for which I dont want to have
I have a treeview with nodes like this: Foo (1234), and want to allow
I have a TreeView that launches a new window when each of its TreeViewItems
My .NET 4 application uses the WPF TreeView which I have enhanced to enable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.