PDA

View Full Version : QTreeWidget and QTextBrowser working together



noobdude
7th June 2011, 01:02
i am trying to create a simple document browser (html) my 'table of contents' or 'index' i implemented using qtreewidget and my html pages are displayed using qtextbrowser. when i click on a qtreewidgetitem i can update the page in qtextbrowser. but when i click on a href link on a page in the qtextbrowser, i cant figure out an easy way to update the qtree to highlight the new page's qtreewidgetitem. is there a simple solution for this or should i be using different widgets? i tried setting qstring data to the qtreewidgetitems and iterating through the items and if the data == the qurl passed from anchorclicked then select the qtreewidgetitem but i couldnt get that to work.

any help greatly appreciated as i am new to qt. :)

Santosh Reddy
7th June 2011, 06:45
i tried setting qstring data to the qtreewidgetitems and iterating through the items and if the data == the qurl passed from anchorclicked then select the qtreewidgetitem but i couldnt get that to work.
What is going wrong when you do this, is the search triggered, if triggered does it give no results?

noobdude
7th June 2011, 14:53
i was setting the data to the "filename.html" and the href link from an html page would be the same but the qurl contains the entire path, which can be different for everybody's computer, so we dont want this. I suppose I could try and take only the qurl text after the last "/" but this seems to be getting more finicky than it needs to be. i thought there would be a better or simpler solution since i have seen this type of thing done before.

noobdude
7th June 2011, 16:58
got it working. I set QString data to each QTreeWidgetItem like I said. (the filename.html) then when i iterated the items if the string.contains(newPage) then setSelected(true) else setSelected(false) and it works. Have to be careful though, because for some reason, the items I hadnt set the data yet would also get selected.