1

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?

Vladimir Bershov
  • 2,701
  • 2
  • 21
  • 51
  • what do you mean by "too angular"? do you mean the "steps" in the rounded corners? these look like aliasing effects; I'm not familiar with the whole Masking thing, but if it's just a binary bit mask then these can't be avoided I think – codeling Apr 27 '22 at 14:18
  • @codeling yes, I mean steps in the rounded corners – Vladimir Bershov Apr 27 '22 at 14:23

1 Answers1

0

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

 QToolTip {
     border: 2px solid darkkhaki;
     padding: 5px;
     border-radius: 10px;
     opacity: 200;
 }
Abdurahmon
  • 148
  • 1
  • 9