Searching bar in tree widget
-
@suslucoder said in Searching bar in tree widget:
I have a search bar, it doesnt set the contains this is my problem
Then can you please explain what you want to do with items you found? Because I don't understand...
-
QList<QTreeWidgetItem*> arama = ui->treeWidget2->findItems(ui->ara->text(), Qt::MatchContains|Qt::MatchRecursive, 0); for(QTreeWidgetItem* item : arama) { ui->treeWidget2->setCurrentItem(item, 0); // item->setBackground(0, Qt::cyan); }
when i comment item->setBackground(0, Qt::cyan);, unless the tree has more than 1 item that at give via ara->text, it show the exactly 1 item.
When i un comment the
item->setBackground(0, Qt::cyan);
the code finds the every item that contains the text, but the text setCurrent item has is blue, the other one is cyan.
When i only wrote
item->setBackground(0, Qt::cyan);
search doesnt work
-
@suslucoder Why do you call setCurrentItem?
-
@suslucoder said in Searching bar in tree widget:
But when i delete it, it doesnt work
In what way it doesn't work? setBackground should work without setCurrentItem, they are unrelated.
-
@suslucoder I debug and, it finds the items but doesnt show me on tree widget
-
Hi,
Why don't you just modify the background of each item of the list and nothing else ?
-
@suslucoder said in Searching bar in tree widget:
When i only wrote
item->setBackground(0, Qt::cyan);search doesnt work
I think arguement for setBackground is QBrush not the color
void QTreeWidgetItem::setBackground(int column, const QBrush &brush) -
@nagesh said in Searching bar in tree widget:
I think arguement for setBackground is QBrush not the color
Can you please elaborate this?
https://doc.qt.io/qt-5/qbrush.html#QBrush-3 -
@SGaist when i modify the background, for highligting the searching items,
even the text was changed, it keep the oldest item.I search for a and highligh its background.
Then i delete a, search for bIt shows me the both a and b
-
@Christian-Ehrlicher thanks for the correction.
@suslucoder it's showing old search items with different color because you have set it's background color in last search..
It's better to set all with default color and matched items in highlight colour for each search