Is it possible to somehow remove a QTableWidget column by title title? I use Qt5

    2 answers 2

    Something like this (an example you need to adapt to your code):

     bool removeColumn(const QString& header) { for (auto columnIndex = 0; columnIndex < columns(); ++columnIndex) { auto headerItem = horizontalHeaderItem(columnIndex); if (headerItem && headerItem->text() == header) { removeColumn(columnIndex); return true; } } return false; } 

      Here are two steps:

      1) Find out the number of the column to be deleted,

      2) Delete the column with the specified number.

      The first is done like this:

      With QTableWidget::horizontalHeaderItem(int column) const we can get a pointer to a QTableWidgetItem , which we can ask for text. Accordingly, it is enough to run through all the columns in order to find out what number the required column has.

      And I would replace removal with shutdown (making invisible):

       table.setColumnHidden(idx, true); // здесь idx - номер столбца 

      But you can also use void QTableWidget::removeColumn(int column) [slot]