How can I put an anchor <a>
into a whatsThis
for a widget an intercept it being clicked?
I know about linkActivated
in a QLabel, or linkClicked
in a QTextBrowser, but I don't know how I can do the same thing with a Whats This text.
To be clear, I want to know if this is possible without interception help events and managing the WhatsThis mechanism on my own.
If I understand your question, it's that you want to know if there is a SIGNAL()
for this. There does not appear to be. Seems you have to watch for the QWhatsThisClickedEvent
by deriving your own Widget class or with some kind of global filter:
http://qtcentre.org/archive/index.php/t-7394.html
FYI, the actual point where the QWhatsThisClickedEvent
is emitted in the Qt sources is here:
http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/kernel/qwhatsthis.cpp#line264
HostileFork's answer is pretty much on the money. One simple approach that may work unless you have widgets which catch WhatsThisClicked
events themselves is to listen for WhatsThisClicked
events in your main window's widget. The code is pretty simple, something like the following:
bool MyMainWindow::event(QEvent* ev)
{
if (ev->type() == QEvent::WhatsThisClicked)
{
ev->accept();
QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(ev);
assert(whatsThisEvent);
QDesktopServices::openUrl(whatsThisEvent->href());
return true;
}
return QMainWindow::event(ev);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With