0

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.

The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189

2 Answers2

2

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!

Antonio Dias
  • 2,751
  • 20
  • 40
0
auto frame = new QWidget(parent, Qt::Popup); 
frame->setStyleSheet("background-color: red; border: 1px solid green; border-radius: 6px;");

QPainterPath path; 
path.addRoundedRect(frame->rect(), 6, 6); 
frame->setMask(path.toFillPolygon().toPolygon());

frame->show();
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Ajax313
  • 1
  • 1
  • 1
    While this code may solve the question, [including an explanation](https://meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Artog Sep 11 '19 at 05:54