Qt Whats This 使用链接/锚点

发布于 2024-12-02 21:11:26 字数 258 浏览 0 评论 0原文

如何将锚点 放入小部件的 whatsThis 中并拦截它被单击?

我知道 QLabel 中的 linkActivated 或 QTextBrowser 中的 linkClicked,但我不知道如何使用 Whats This 文本执行相同的操作。

需要明确的是,我想知道如果不拦截帮助事件并自行管理 WhatsThis 机制,这是否可能。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

说好的呢 2024-12-09 21:11:26

如果我理解你的问题,那就是你想知道是否有一个 SIGNAL() 。似乎没有。似乎您必须通过派生您自己的 Widget 类或使用某种全局过滤器来监视 QWhatsThisClickedEvent

http://qtcentre.org/archive/index.php/t-7394.html

仅供参考,实际点QWhatsThisClickedEvent 在 Qt 源中发出:

http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/kernel/qwhatsthis.cpp#line264

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

你又不是我 2024-12-09 21:11:26

HostileFork 的答案几乎就是金钱。除非您有自己捕获 WhatsThisClicked 事件的小部件,否则一种可能有效的简单方法是在主窗口小部件中侦听 WhatsThisClicked 事件。代码非常简单,如下所示:

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);
}

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文