c++qtstylesheetqwidgetqframe

Qt Balloon Window from QFrame


I would like to create my own Balloon window for tips in Qt. I'm starting by creating a window with round corners.

I'm using a class inherited from QFrame. The class's constructor contains:

this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
Pal.setColor(QPalette::Background, Qt::yellow);
this->setAutoFillBackground(true);
this->setPalette(Pal);
this->setStyleSheet("QFrame {border-style: solid; border-width: 10px;"
                    "border-radius: 100px;"
                    "min-width: 10em; background-clip: padding; background-origin: content;}");

But this is not creating round corners when showing using the show() member function. I'm getting this:

enter image description here

How can I get rid of those rectangular edges and have them transpararent colored?

If you require any additional information, please ask.


Solution

  • If my guess is correct you are looking for something like setMask !

    Basically what you need to do is draw a rectangle with your desired radius and then convert it to QRegion to use it with setMask. See below one way:

    QPainterPath path;
    path.addRoundedRect(rect(), 100, 100);
    QRegion region = QRegion(path.toFillPolygon().toPolygon());
    setMask(region);
    

    And that will be the result:

    enter image description here

    Hope that helps!