开发者

Qt Whats This using a link/anchor

开发者 https://www.devze.com 2023-04-02 11:28 出处:网络
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开发者_C百科 in a QTextBrowser, but I don\'t know

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开发者_C百科 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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消