Nominate our 2022 Qt Champions!

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--) { 

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


    but saw no effect.

    If I use


    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:

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

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