Mikhail
Mikhail

Reputation: 8028

Test if QToolTip is obsucred before displaying

I'm using a QWindow to contain some heavily optimized OpenGL code.

To facilitate user interaction I have a mode where data under the cursor is displayed in the tooltip.

This leads to a UX problem when another window obscures the one sending the tooltip event. In the following screenshot, the tooltip is draw on top of a Firefox window (which is undesired).

What is the paradigmatic solution? Is there a way to test if part of a window is obscured?

enter image description here

The function calling the tooltip looks something like:

if (!qIsNaN(value_under_cursor))
{
    auto state = QApplication::applicationState();
    auto text = QString::number(value_under_cursor, 'f', 3);
    static QString old_value;
    if (text != old_value)
    {
        auto static last_show = timestamp();
        auto now = timestamp();
        auto re_raster = ((now - last_show) >= ms_to_chrono(100));
        if (re_raster)
        {
            QToolTip::showText(current_mouse_coordinates_in_global, text);
            last_show = now;
        }
    }
    old_value = text;
}

Upvotes: 0

Views: 61

Answers (1)

w1ck3dg0ph3r
w1ck3dg0ph3r

Reputation: 1011

I don't know if there is a cross-platform way to test if specific region is obscured by another apps window, but you can:

  • check if your window is in focus (QWindow::isActive(), IIRC) and only show tooltip if it is, or
  • render tooltip using OpenGL.

Upvotes: 2

Related Questions