Anton1978
Anton1978

Reputation: 35

Can I set the time when toolTip appears on QGraphicsItem?

Good afternoon. The toolTip on QGraphicsItem appears after about one second. Can this value be changed? If so, how?

Upvotes: 1

Views: 327

Answers (1)

Pavan Chandaka
Pavan Chandaka

Reputation: 12831

Probably you can give a try using

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

You need to handle the QEvent::ToolTip in your event handling code. I lifted that piece of code from documentation. And below it is. (Note: I did not test this.)

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

Upvotes: 1

Related Questions