繁体   English   中英

我可以设置工具提示出现在 QGraphicsItem 上的时间吗?

[英]Can I set the time when toolTip appears on QGraphicsItem?

下午好。 QGraphicsItem 上的工具提示会在大约一秒钟后出现。 这个值可以改变吗? 如果是这样,怎么做?

可能您可以尝试使用

void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect, int msecDisplayTime)

您需要在事件处理代码中处理QEvent::ToolTip 我从文档中提取了那段代码。 下面是。 (注意:我没有对此进行测试。)

//CREATE AN EMPTY RECT
QRect rect();

//HANDLE THE QEvent::ToolTip
if (event->type() == QEvent::ToolTip) {
        QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
        int index = itemAt(helpEvent->pos());
        if (index != -1) {

        //HERE YOU CAN CONTROL TIME.
            QToolTip::showText(helpEvent->globalPos(), shapeItems[index].toolTip(), nullptr,rect,<<TIME YOU WANT TO SET>>);
        } else {
            QToolTip::hideText();
            event->ignore();
        }

        return true;
    }
    return QWidget::event(event);
}

暂无
暂无

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

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