7

I have a QTableWidget with 7 colums in a QDialog, where every row has information about files in a specific directory. With some checkboxes, lineedits etc I want to have the possibility to show only those files with a certain text, which I can manually add in the lineEdit.

Is it somehow possible to check every row, if it contains the lineEdit-text and if not to hide the row (without changing any index of the other rows, that I dont have to hide)?

scopchanov
  • 7,966
  • 10
  • 40
  • 68
erniberni
  • 313
  • 5
  • 17
  • 1
    From what I understand, in each row there is an item that contains a text, you want those rows to be that text is equal to the text that appears in a QLineEdit. Am I right? – eyllanesc Jan 08 '18 at 06:51
  • Yes, exactly. I found this: QTableWidget->hideRow(int i). Does it work with that? – erniberni Jan 08 '18 at 06:51
  • 1
    yes, use the textChanged method of QLineEdit, and in the slot you use iterates over the items, and if it does not meet the criterion, hide the row with that method – eyllanesc Jan 08 '18 at 06:53
  • Thank you, it works perfect! :) – erniberni Jan 08 '18 at 06:59

1 Answers1

6

For people who need this possibility, it is quite easy, I do it like this:

for(int i=0; i<tableWidget->rowCount(); i++)
{
    if(lineEdit->text() != tableWidget->(i, 0)->text())
    {
         tableWidget->hideRow(i);
    }
}
erniberni
  • 313
  • 5
  • 17