简体   繁体   English

工具提示中的Qt WIdget

[英]Qt WIdget inside ToolTip

Is it, maybe by using some dirty hakish stuff, possible to use a QWidget as a tooltip or archive a similar mechanic? 是否可以通过使用一些肮脏的混蛋来将QWidget用作工具提示或归档类似的机制? I want to have such a thing, because I have a list of some participants for a contest and would like to use a QListView for displaying everyone inside that contest when I hover the total participant count. 我想拥有这样的东西,因为我有一个竞赛的一些参与者的列表,并且当我悬停总参与者数时,想使用QListView来显示该竞赛中的所有人。 I'm using Qt5.3 . 我正在使用Qt5.3

A QToolTip can contain and display rich text, so you could create a the look of a table by using the HTML tags that are supported (see here ). QToolTip可以包含并显示富文本格式,因此您可以使用受支持的HTML标记创建表的外观(请参见此处 )。

If that does not suffice for your case, then you could always create your custom widget and display it at the right time by listening to the right events: QEvent::ToolTip would seem the right one. 如果这不足以满足您的情况,那么您始终可以创建自定义窗口小部件,并通过听正确的事件在正确的时间显示它: QEvent::ToolTip似乎是正确的。 Overriding QWidget::event(QEvent *) would give you something like: 重写QWidget::event(QEvent *)将为您提供以下信息:

bool MyWidget::event(QEvent * event) override
{
    if ( event->type() == QEvent::ToolTip )
    {
        myToolTip_->show();
    }
}

But then you'd need to place your tooltip widget at the correct position, take care of hiding it when not needed anymore and so on... So I'd try the rich text version first. 但是随后您需要将工具提示窗口小部件放置在正确的位置,并在不再需要它时将其隐藏,以此类推……因此,我将首先尝试使用RTF版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM