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

问题描述 投票:1回答:1

下午好。大约一秒钟后,将出现QGraphicsItem上的toolTip。可以更改此值吗?如果是这样,如何?

c++ qt qt5
1个回答
0
投票

可能您可以尝试使用

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);
}
© www.soinside.com 2019 - 2024. All rights reserved.