void MainWindow:
n_lineEdit_textChanged(const QString &search)
{
QList<QLabel *> labels = findChildren<QLabel *>();
QList<QPushButton *> buttons = findChildren<QPushButton *>();
// handle empty search by showing all buttons and exiting
if (search.isEmpty())
{
foreach (QPushButton *b, buttons)
b->show();
foreach (QLabel *b, labels)
b->show();
return;
}
// search buttons for any matching "search" and hide everything not matching
foreach (QPushButton *b, buttons)
{
if (b->text().contains(search, Qt::CaseInsensitive))
b->show();
else
b->hide();
foreach (QLabel *b, labels)
{
if (b->text().contains(search, Qt::CaseInsensitive))
b->show();
else
b->hide();
}
}
}
Bookmarks