Labels

Thursday, September 29, 2011

How to redirect to online webpage when click a link in Whatsthis rich text

If the text is rich text and the user clicks on a link, the widget also receives a QWhatsThisClickedEvent with the link's reference as QWhatsThisClickedEvent::href().
If a QWhatsThisClickedEvent is handled (i.e. QWidget::event() returns true), the help window remains visible. Call QWhatsThis::hideText() to hide it explicitly.
Reimplement QWidget::event() and catch QEvent::WhatsThisClicked. It can be done more or less in this way:

bool CSDQueuesWindow::eventFilter(QObject *obj, QEvent *ev)
{
  if(ev->type()==QEvent::WhatsThisClicked)
  {
   QWhatsThisClickedEvent* whatsclicked = static_cast<QWhatsThisClickedEvent*>(ev);
   QDesktopServices::openUrl(QUrl(whatsclicked->href())); // redirect to the linked bomgar webpages
   return true;
  }
  return QWidget::eventFilter(obj,ev); // call base class!
 
}

No comments:

Post a Comment