Results 1 to 5 of 5

Thread: ignore following link in anchorClicked()

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default ignore following link in anchorClicked()

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: ignore following link in anchorClicked()

    Did you try disconnecting the anchorClicked signal from the setSource slot?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ignore following link in anchorClicked()

    Quote Originally Posted by wysota
    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

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ignore following link in anchorClicked()

    try

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

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

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ignore following link in anchorClicked()

    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:
    Qt Code:
    1. ...
    2. str += "<tr bgcolor=\"#dddddd\"><td>ID</td><td colspan=\"3\">";
    3. str += "<a ";
    4. str += "name=\"" + obj->ID() + "\" ";
    5. str += "href=\"" + obj->ID() + "\">";
    6. str += obj->ID() + "</a></td></tr>";
    7. ...
    To copy to clipboard, switch view to plain text mode 


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

    Qt Code:
    1. void Object_Widget::followLink(const QUrl& url)
    2. {
    3. // textbrowser shows the same document but scrolls to the top
    4. textBrowser_properties->setSource(QUrl());
    5. // scroll to the link which was clicked
    6. textBrowser_properties->scrollToAnchor(url.toString());
    7.  
    8. try {
    9. model::Object& obj = model::System::object(url.toString());
    10. model_gui::SingleObject_Widget* so =
    11. new model_gui::SingleObject_Widget(0,Qt::WindowStaysOnTopHint);
    12. so->object(&obj);
    13. so->show();
    14. } catch (model::NoSuchObject_Exception e) {
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

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

    jh

Similar Threads

  1. Text Browser Link Question
    By taylor34 in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2006, 19:54
  2. Problem with libmng on static link
    By jlbrd in forum Installation and Deployment
    Replies: 2
    Last Post: 10th May 2006, 22:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.