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. Can't hide QTableView column after 'resetting' the QAbstractTableModel [Qt 5.5.1]

Can't hide QTableView column after 'resetting' the QAbstractTableModel [Qt 5.5.1]

Scheduled Pinned Locked Moved General and Desktop
hide columnqtableviewhidecolumnqheaderview
4 Posts 2 Posters 1.9k 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.
  • P Offline
    P Offline
    Phil_W
    wrote on last edited by Phil_W
    #1

    After resetting our QAbstractTableModel (subclass), attempting to hide a column no longer works.

    After the model reset, when calling QTableView::hideColumn(int), I can see that QHeaderView::setSectionHidden() method always "gives up", thinking that the private "isVisualIndexHidden" state for that column is already in the hidden state. That is, this QHeaderView method is always exiting from line 11; it never gets to line 13 (i.e. after the model reset). However, the column remains visible on the screen.

    01: void QHeaderView::setSectionHidden(int logicalIndex, bool hide)
    02: {
    03:     Q_D(QHeaderView);
    04:     if (logicalIndex < 0 || logicalIndex >= count())
    05:         return;
    06: 
    07:     d->executePostedLayout();
    08:     int visual = visualIndex(logicalIndex);
    09:     Q_ASSERT(visual != -1);
    10:     if (hide == d->isVisualIndexHidden(visual))
    11:         return;
    12:     if (hide) {
    13:         int size = d->headerSectionSize(visual);
    14:         if (!d->hasAutoResizeSections())
    15:             resizeSection(logicalIndex, 0);
    16:         d->hiddenSectionSize.insert(logicalIndex, size);
    17:         d->setVisualIndexHidden(visual, true);
    18:         if (d->hasAutoResizeSections())
    19:             d->doDelayedResizeSections();
    20:     } else {
    21:         int size = d->hiddenSectionSize.value(logicalIndex, d->defaultSectionSize);
    22:         d->hiddenSectionSize.remove(logicalIndex);
    23:         d->setVisualIndexHidden(visual, false);
    24:         resizeSection(logicalIndex, size);
    25:     }
    26: }
    

    I have also tried calling reset() on the QHeaderView after finishing the QAbstractTableModel reset (i.e. after the call to QAbstractItemModel::endResetModel()). That didn't help.

    Is this a known problem in Qt 5.5.1?
    (We're on Windows. This was not a problem with our prior Qt version, Qt 4.8.5).

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      To check if it's something known, you should take a look at the bug report system. If you can't find anything there, please consider opening a new report providing a minimal compile example that those the behaviour.

      You might also want to try a more recent version of Qt.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Phil_W
        wrote on last edited by
        #3

        We were able to solve the problem (in Qt 5.5.1) by recreating the QTableView's two QHeaderViews. We do this after changing the number of, or visibilty of rows or columns.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Glad you found a solution !

          Can you share a small sample code that triggers this behaviour ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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