Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Whats This using a link/anchor

Tags:

c++

qt

qt4

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.

like image 909
edA-qa mort-ora-y Avatar asked Feb 24 '23 01:02

edA-qa mort-ora-y


2 Answers

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

like image 62
HostileFork says dont trust SE Avatar answered Mar 08 '23 06:03

HostileFork says dont trust SE


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);
}
like image 42
Craig Scott Avatar answered Mar 08 '23 07:03

Craig Scott