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 add text to second column along with first?

How to add text to second column along with first?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 403 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.
  • S Offline
    S Offline
    SRaD
    wrote on last edited by
    #1

    Using Qt5, I have a TreeModel which inherits QAbstractItemModel. I have two colums in the view. I can dynamically add a checkbox with a label to the first column using the following:

    QCheckBox *cb = new QCheckBox;
    cb->setCheckState(Qt::Checked);
                                                                               
    QVector<QVariant> myData;
    myData << name << QVariant::fromValue(cb);
                                                                               
    MyTreeItem *myItem = new MyTreeItem(myData, mainItem);
    myItem->set_label(sname);
    
    mainItem->appendChild(myItem);
    

    What I'd like to do now is add a text string to the second column on the same row where I added this MyTreeItem.

    How might that be done?

    1 Reply Last reply
    0
    • I Offline
      I Offline
      iss7gli7
      wrote on last edited by
      #2

      @srad said in How to add text to second column along with first?:

      new MyTreeItem

      In examples, method data for TreeModel has form:

      QVariant TreeModel::data(const QModelIndex &index, int role) const
      {
          if (!index.isValid())
              return QVariant();
      
          if (role != Qt::DisplayRole)
              return QVariant();
      
          TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
      
          return item->data(index.column());
      }
      

      And for TreeItem method data:

      QVariant TreeItem::data(int column) const
      {
          return m_itemData.value(column);
      }
      

      Your case depends on your implementation that methods and constructor of MyTreeItem.

      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