Searching bar in tree widget
-
wrote on 29 Mar 2021, 11:00 last edited by
I have the code below for searching items in tree widget. I doesnt search. When i finish editing, i cant see any item on widget.
It doesnt have any error. But when i debug, i saw that "arama" is emptyvoid MainWindow::on_ara_editingFinished() { QList<QTreeWidgetItem*> arama = ui->treeWidget2->findItems(ui->ara->text(), Qt::MatchContains, 0); for(QTreeWidgetItem* item : arama) { qDebug() << ui->ara->text(); ui->treeWidget2->setCurrentItem(item); } }
-
I have the code below for searching items in tree widget. I doesnt search. When i finish editing, i cant see any item on widget.
It doesnt have any error. But when i debug, i saw that "arama" is emptyvoid MainWindow::on_ara_editingFinished() { QList<QTreeWidgetItem*> arama = ui->treeWidget2->findItems(ui->ara->text(), Qt::MatchContains, 0); for(QTreeWidgetItem* item : arama) { qDebug() << ui->ara->text(); ui->treeWidget2->setCurrentItem(item); } }
@suslucoder What does ui->ara->text() return? In which column do you want to search? Is there at least one item in the tree widget in the column you're searching containing the text ui->ara->text() returns?
-
@suslucoder What does ui->ara->text() return? In which column do you want to search? Is there at least one item in the tree widget in the column you're searching containing the text ui->ara->text() returns?
wrote on 29 Mar 2021, 12:19 last edited by@jsulm
I've changed my code toQList<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::red); }
but setCurrentItem is set one item..of course...
But i want to see every item that contains the given text
-
@jsulm
I've changed my code toQList<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::red); }
but setCurrentItem is set one item..of course...
But i want to see every item that contains the given text
@suslucoder said in Searching bar in tree widget:
But i want to see every item that contains the given text
-
@suslucoder said in Searching bar in tree widget:
But i want to see every item that contains the given text
wrote on 29 Mar 2021, 12:44 last edited by@jsulm you suggest me to use setSelected ?
-
@jsulm you suggest me to use setSelected ?
@suslucoder Yes, I do - you want to select items, right? The method I suggested does exactly that...
-
@suslucoder Yes, I do - you want to select items, right? The method I suggested does exactly that...
wrote on 29 Mar 2021, 12:47 last edited by@jsulm No, i dont want to select :D
I have a search bar, it doesnt set the contains this is my problem -
@jsulm No, i dont want to select :D
I have a search bar, it doesnt set the contains this is my problem@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...
-
@jsulm No, i dont want to select :D
I have a search bar, it doesnt set the contains this is my problemwrote on 29 Mar 2021, 12:52 last edited by deleted286QList<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
-
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 Why do you call setCurrentItem?
wrote on 29 Mar 2021, 12:57 last edited by@jsulm yes i dont i know why im using it.
I saw in somewehere.
But when i delete it, it doesnt work -
@jsulm yes i dont i know why im using it.
I saw in somewehere.
But when i delete it, it doesnt work@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 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.
wrote on 29 Mar 2021, 13:05 last edited by@jsulm when i delete
ui->treeWidget2->setCurrentItem(item, 0);
the hole code doesnt work. without any error messages
-
@jsulm when i delete
ui->treeWidget2->setCurrentItem(item, 0);
the hole code doesnt work. without any error messages
wrote on 29 Mar 2021, 13:15 last edited by@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 ?
-
wrote on 29 Mar 2021, 23:54 last edited by
@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 -
wrote on 30 Mar 2021, 10:28 last edited by
@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
-
wrote on 30 Mar 2021, 12:00 last edited by
@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
4/19