PDA

View Full Version : ignore following link in anchorClicked()



jh
3rd July 2006, 21:34
hi,

i have a qtextbrowser which shows some text with hrefs. clicking on a link
a new widget should be created and be shown. the link is not an url but only
a string which is interpreted in a slot connected to anchorClicked().
problem is that the textbrowser handles navigation automatically when
setSource is not be called in the slot. actually, i want the textbrowser do
nothing, i.e. i connect anchorClicked() to a slot, do something with the passed
string in the slot but the textbrowser should not do anything.
any chance to turn off the default handling of anchors?

best regards,
jh

wysota
4th July 2006, 09:42
Did you try disconnecting the anchorClicked signal from the setSource slot?

jh
15th July 2006, 13:36
Did you try disconnecting the anchorClicked signal from the setSource slot?

yes. in that case the textbrowser is cleared.

the textbrowser should do nothing except emiting signal anchorClicked.
even if i disconnect everthing (textBrowser->disconnect()) the textbrowser
is cleared.

jh

munna
15th July 2006, 13:53
try

"<a href = \"#\">your text here</a>"

Clicking on the link will only emit the signal and do nothing else.

jh
16th July 2006, 16:33
unfortunately this also did not not work. same behaviour. textbrowser is cleared.

so i did the following:
- adding an anchor name to each link.
- in method 'follow_link(const QUrl&)' which is connected to
signal 'anchorClicked()' i set an empty url as source an scroll to the
named anchor:

part of the method which generates the html text which is shown in the textbrowser:


...
str += "<tr bgcolor=\"#dddddd\"><td>ID</td><td colspan=\"3\">";
str += "<a ";
str += "name=\"" + obj->ID() + "\" ";
str += "href=\"" + obj->ID() + "\">";
str += obj->ID() + "</a></td></tr>";
...



this method gets an clicked link (which containes the ID of
an object) and opens a new widget.



void Object_Widget::followLink(const QUrl& url)
{
// textbrowser shows the same document but scrolls to the top
textBrowser_properties->setSource(QUrl());
// scroll to the link which was clicked
textBrowser_properties->scrollToAnchor(url.toString());

try {
model::Object& obj = model::System::object(url.toString());
model_gui::SingleObject_Widget* so =
new model_gui::SingleObject_Widget(0,Qt::WindowStaysOn TopHint);
so->object(&obj);
so->show();
} catch (model::NoSuchObject_Exception e) {
}
}


this works for me but getting rid of that automatic following of
links would be much better i think.

jh