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


  • Lifetime Qt Champion

    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.



  • 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.


  • Lifetime Qt Champion

    Glad you found a solution !

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



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.