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. table multi level header not show labels
QtWS25 Last Chance

table multi level header not show labels

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

    I added a multi level header like this:
    0_1563811252423_Screen Shot.png
    The multi header is ok when program start up, but when i add another one, it should be "channel 17", it's not show all the labels. The code like this:

    int icols = table->columnCount();
        for (int i = 0; i < 5; ++i)
        {
            table->insertColumn(icols + i);
        }
        hHeader->model()->insertColumns(icols, 5);
        hHeader->setSpan(0, icols, 1, 5);
    
        hHeader->setCellLabel(0, icols, "channel " + QString::number((icols - 2) / 5 + 1));
        hHeader->setCellLabel(1, icols, "A");
        hHeader->setCellLabel(1, icols + 1, "f");
        hHeader->setCellLabel(1, icols + 2, "Ø");
        hHeader->setCellLabel(1, icols + 3, "t1");
        hHeader->setCellLabel(1, icols + 4, "t2");
    
    void GridTableHeaderView::setCellLabel(int row, int column,
                                           const QString &label) {
    //    qDebug() << "set row=" << row << "set col=" << column;
      QModelIndex index =model()->index(row, column);
      model()->setData(index, label, Qt::DisplayRole);
    }
    
    bool GridTableHeaderModel::setData(const QModelIndex &index,
                                       const QVariant &value, int role) {
      if (index.isValid()) {
    //      qDebug() << "index row=" << index.row() << "col=" << index.column();
        TableHeaderItem *item =
            static_cast<TableHeaderItem *>(index.internalPointer());
        if (role == ColumnSpanRole) {
          int col = index.column();
          int span = value.toInt();
          if (span > 0) {
            if (col + span - 1 >= _column)
              span = _column - col;
            item->setData(span, ColumnSpanRole);
          }
        } else if (role == RowSpanRole) {
          int row = index.row();
          int span = value.toInt();
          if (span > 0) {
            if (row + span - 1 > _row)
              span = _column - row;
            item->setData(span, RowSpanRole);
          }
        } else
          item->setData(value, role);
        return true;
      }
      return false;
    }
    
    void TableHeaderItem::setData(const QVariant &data, int role) {
        qDebug() << "role=" << role << "data=" << data;
      m_itemData.insert(role, data);
    }
    
    class TableHeaderItem {
    public:
      TableHeaderItem(TableHeaderItem *parent = 0);
      TableHeaderItem(int row, int column, TableHeaderItem *parent = 0);
    
      TableHeaderItem *insertChild(int row, int col);
      TableHeaderItem *child(int row, int col);
    
      TableHeaderItem *parent();
    
      int row() const;
      int column() const;
    
      void setData(const QVariant &data, int role);
      QVariant data(int role) const;
    
      void clear();
    
      bool removeColumns(int position, int columns);
      bool insertColumns(int position, int columns);
    
    private:
      TableHeaderItem *m_parentItem;
      int _row;
      int _column;
    
      QHash<QPair<int, int>, TableHeaderItem *> m_childItems;
      QHash<int, QVariant> m_itemData;
    };
    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