March 28, 2012

Raadush Raadush
Lab Rat
1 posts

Multiple hyperlinks in one label text


Hi guys,
I have this question. I can simply evaluate hyperlink in label text by using linkActivated like in this example:

  1. label->setText("Some message. <ahref=\" \">Agree</a>");
  2. connect(label, SIGNAL(linkActivated(const QString & )), this, SLOT(agree()));

But is there some way to react on multiple hyperlinks in one label text differently? Let say I have:
  1. label->setText("Some message. <ahref=\" \">Agree</a>, or you can always <ahref=\" \">Cancel</a>.");

And all I want do do is to connect signal from hyperlink Agree to agree() slot and signal from hyperlink Cancel to cancel() slot.
Thanks ;)
(btw I know I have some errors in sytax, but I had to change it a little for this post to be displayed correcly – meaning ahref and spaces after SIGNAL and SLOT)

Edit: Please use @ tags around code sections, that also solves your layout issue; Andre

1 reply

March 28, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2068 posts

The linkActivated() signal passes the clicked link, which makes it rather easy to react differently (given that meaningful link names are provided).

  1. setText("<a href='agree'>Agree</a>, or you can always <a href='cancel'>Cancel</a>.");
  3. void activateLink(const QString &link)
  4. {
  5.     if (link == "agree")
  6.     {
  7.         agree();
  8.     }
  9.     else if (link == "cancel")
  10.     {
  11.         cancel();
  12.     }
  13. }

  ‹‹ [Solved] blob data in sql server 2008      [SOLVED] Retrieve the colours used by Qt to render a frame of StyledPanel shape ››

You must log in to post a reply. Not a member yet? Register here!