removeColumn in QTableWidget too slow



  • Hi,

    I have a QTableWidget that is filled with a 2D QVector. There is a "compact view" option which basically shows only part of the vector depending on the item value, so after inserting the data I have to remove the unnecessary columns.

    Currently, I'm setting up the QTableWidget with all columns (setColumnCount(540); for testing), then fill in the data and delete the columns in a loop:

    for (int vC = vColumnsTotal - 1; vC > vMaxColumn-1; vC--) { 
            removeColumn(vC);
        }
    

    But this is extremely slow. Filling the table takes about 2 seconds, removing the columns about 40-50 seconds. I've tried:

    setUpdatesEnabled(false);
    setDisabled(true);
    setVisible(false);
    

    but saw no effect.

    If I use

    setColumnCount(vMaxColumn);
    

    instead it works very fast, but presumably that only works if I want to remove the last columns which won't necessarily be the case later in the code.

    Is there anything I can disable to make the removal faster? Thanks.



  • Do not remove, just hide: http://doc.qt.io/qt-5/qtableview.html#setColumnHidden

    for (int vC = vColumnsTotal - 1; vC > vMaxColumn-1; vC--) { 
            setColumHidden(vC,true);
        }
    


  • Thanks, hiding the column works a lot faster. I'm not sure it that'll give me other problems but for now I made it work.


Log in to reply
 

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