QToolTip background-color is not clipped with border radius

1.2k Views Asked by At

I have styled my tooltips like this (not really that colors)

QToolTip {
    border: 1px solid blue;
    border-radius: 10px;
    background-color: red;
}

But the background is not clipped at the corners:

enter image description here

Why is it not clipped?

1

There are 1 best solutions below

0
On

Two years after your question was asked, struggling with the same issue, using experiments and hard googling I came to the following:

  • You can't get what you want with css only, not with widgets
  • QToolTip is actually a QLabel
  • Implementing custom tooltip is a bit more job, but only a bit: setAttribute(Qt::WA_TranslucentBackground); + setMask() work fine, as well as other, simplier ways to implement widget transparency

At last, if you are really into it, recursively walking over widget's children and installing event filter could be a sufficient solution, smth like:

if (event->type() == QEvent::ToolTip) {
    QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
    // Your code here
    return true;
}

Easier it is if you don't wish to have those tooltips everywhere. Sometimes you already have to do something similar to apply complex CSS styles from files to dynamically created widgets, but anyway that's not a "codeless solution". Alas, couldn't find a better way up to now.