Qt Windows: Rounded ToolTips

235 views Asked by At

I need rounded tooltips in Qt5 + Windows. Rounded corners for tooltips cannot be set via stylesheet, the following stylesheet is not working:

QToolTip
{
    font-family: Calibri;
    font-size: 13pt;
    border-radius: 0.5em;
    ...
}

I cannot override tootip events for widgets, because our application has too many places where tootips are shown. I'm trying to do it in the following way:

int ThemeStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
{    
    switch (hint)
    {
    case SH_ToolTip_Mask:
    {
    if (option) 
    {
        if (QStyleHintReturnMask* mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) 
        {
            static const int cornerRadius = 5;

            QPainterPath path;
            path.addRoundedRect(option->rect, cornerRadius, cornerRadius);

            mask->region = QRegion(path.toFillPolygon().toPolygon()); // Unable to use QPolygonF ?
        }
    }       
    }
    break;
//....

As a result, I get too angular corners:

enter image description here

Is there some global way to make smooth rounded tootips in Qt5?

1

There are 1 answers

0
Abdurahmon On

You're giving border radius in em, try this style sheet:

 QToolTip {
     border: 2px solid darkkhaki;
     padding: 5px;
     border-radius: 10px;
     opacity: 200;
 }