How to hide a row of a QTableWidget without changing the index of the entries?
Asked Answered
F

1

9

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

Farnsworth answered 8/1, 2018 at 6:43 Comment(4)
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?Waltraudwaltz
Yes, exactly. I found this: QTableWidget->hideRow(int i). Does it work with that?Farnsworth
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 methodWaltraudwaltz
Thank you, it works perfect! :)Farnsworth
F
10

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);
    }
}
Farnsworth answered 9/1, 2018 at 6:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.