PDA

View Full Version : linking in QWhatsThis



Greenmanspirit
4th June 2007, 17:47
I am working on a help system and we want to use links in the QWhatsThis object to connect with our online help viewer eg. setup like "Blah blah blah, for more information go here" with here being a link. My partner and I have been looking online for the past few days to find any tips or hints about how to do this and have found nothing of use. Does anyone know how to program the QWhatsThis to react to the link being clicked?

jpn
4th June 2007, 19:29
From QWhatsThis docs:


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.

Greenmanspirit
4th June 2007, 19:33
we saw that, but how do you actually implement dealing with the QWhatsThisEvent, we are both very new to Qt, our boss told us to start looking at this stuff a few days ago.

jpn
4th June 2007, 19:40
Reimplement QWidget::event() and catch QEvent::WhatsThisClicked. It can be done more or less in this way:


bool MyWidget::event(QEvent* event)
{
if (event->type() == QEvent::WhatsThisClicked)
{
QWhatsThisClickedEvent* clicked = static_cast<QWhatsThisClickedEvent*>(event);
QDesktopServices::openUrl(clicked->href()); // do something with the link
return true; // what's this remains open if true is returned
}
return QWidget::event(event); // call base class!
}

Greenmanspirit
4th June 2007, 20:02
thanks, we really appreciate it, you have ended our many days of confusion.