[Qt-interest] Ret: Re: QDialog with rounded "corners"
Markus Franke
Franke.M at sebakmt.com
Fri Feb 11 11:04:55 CET 2011
Dear all,
thanks for the many replies. However none of them really worked for me.
I have found a different solution now which I want to share with you.
Maybe somebody can benefit from this in the future.
---snip---
void MyDialog::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event)
updateMask();
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); // we need this in
order to get correct rounded corners
painter.setPen(QPen(QBrush(Qt::black), 2.0));
painter.setBrush(QBrush(QColor(Qt::yellow)));
painter.drawRoundedRect(rect().adjusted(2,1,-2,-1), 5, 5);
}
QRegion MyDialog::getRegion() const
{
QPainterPath path;
path.addRoundedRect(rect().adjusted(1, -1, -1, 0), 6, 6);
return QRegion(path.toFillPolygon().toPolygon());
}
void MyDialog::updateMask()
{
QBitmap Bitmap(size());
Bitmap.clear();
QPainter Painter(&Bitmap);
Painter.setClipRegion(getRegion());
Painter.fillRect(rect(), Qt::color1);
Painter.end();
setMask(Bitmap);
}
---snip---
Best regards,
Markus Franke
qt-interest-bounces+franke.m=sebakmt.com at qt.nokia.com schrieb am
11.02.2011 07:16:41:
> Hello!
>
> You need code like that:
>
> QPalette palette;
> palette.setColor(QPalette::Base, Qt::transparent);
> yourWidget.setPalette(palette);
> yourWidget.setAttribute(Qt::WA_TranslucentBackground);
>
> I used it with QML:
>
> int main(int argc, char *argv[])
> {
> QApplication a(argc, argv);
> QDeclarativeView view;
> // enable semi-transparent
> QPalette palette;
> palette.setColor(QPalette::Base, Qt::transparent);
> view.setPalette(palette);
> view.setAttribute(Qt::WA_TranslucentBackground);
>
> // loading QML from file
> view.setSource(QUrl::fromLocalFile("../qml1/qml1.qml"));
>
> // disable OS GIU form-control
> view.setWindowFlags(Qt::FramelessWindowHint);
>
> view.show();
>
> return a.exec();
> }
>
> --
> Sincerely, Philipp Tkachev.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
"Disclaimer: This message is intended only for the use of the individual
or entity to
which it is addressed and may contain information which is privileged,
confidential, proprietary,
or exempt from disclosure under applicable law. If you are not the
intended recipient or the person
responsible for delivering the message to the intended recipient, you are
strictly prohibited from
disclosing, distributing, copying, or in any way using this message. If
you have received this
communication in error, please notify the sender and destroy and delete
any copies you may have
received."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110211/878b41d4/attachment.html
More information about the Qt-interest-old
mailing list