Qt4: Transparent Window with Rounded Corners

QT4: Transparent Window with rounded corners

I had a similar problem where I wanted to paint on a toplevel widget and have only the painted part appear. setWindowOpacity changed the opacity of the painted part, which I didn't want.

this->setAttribute(Qt::WA_TranslucentBackground, true);

changed the opacity of the widget without the painted part. I just tried tossing on a button, and that also displays perfectly opaque. So you should be able to display other children however you like.

Top round transparent window

Adding an answer, just so I can post an image to prove to you that all you need is to set the color:

Window {
id: app
visible: true
width: 70
height: 70

flags: Qt.Window | Qt.FramelessWindowHint

color: "#00000000"

Rectangle {

anchors.fill: parent
radius: parent.width / 2.0

color: ma.pressed ? "red" : "black"

MouseArea {
id: ma
property point clickPos: "1,1"

anchors.fill: parent
drag.target: parent

onPressed: {
clickPos = Qt.point(mouse.x,mouse.y)
}

onPositionChanged: {
var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
app.x += delta.x;
app.y += delta.y;
}

onDoubleClicked: app.close()
}
}
}

And the result:

Sample Image

I didn't use any of the flags you are setting from C++, maybe setDefaultAlphaBuffer() is breaking it for you.

QFrame round border transparent background

I think you cannot resolve the problem using style sheets. QMenu is a rectangular top-level widget.

Is this your QMenu? If so, try this:

this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);

Replace this by your instantiated QMenu object.

Of course, you could also use setMask to hide the required region. For example:

QRegion region (menu->x(),
menu->y(),
menu->sizeHint().width(),
menu->sizeHint().height(),
QRegion::Ellipse);
menu->setMask(region);

Qt5 & QtQuick2 - transparent main window

This works for me under Windows 8 and Ubuntu 12.04.

import QtQuick 2.3
import QtQuick.Window 2.2

Window {
width: 300
height: 300
flags: Qt.FramelessWindowHint | Qt.Window
color: "transparent"

Rectangle {
color: "brown"
anchors.fill: parent
anchors.margins: 10
}
}

QT 5.7 QML quick semi-transparent rectangle, with rounded corners on one side

You could use clipping (see performance docs) to cut off the corners of a single rounded rectangle:

import QtQuick 2.5
import QtQuick.Window 2.2

Window {
width: 300
height: 300
visible: true

Item {
width: 100
height: 100
anchors.centerIn: parent
clip: true

Rectangle {
anchors.fill: parent
anchors.rightMargin: -radius
radius: 10
color: "navajowhite"
opacity: 0.5
}
}
}

You could also use layers to avoid the overlapping transparency issue:

import QtQuick 2.5
import QtQuick.Window 2.2

Window {
width: 300
height: 300
visible: true

Item {
width: 100
height: 100
opacity: 0.5
layer.enabled: true
anchors.centerIn: parent

Rectangle {
color: "navajowhite"
radius: 10
anchors.fill: parent
}
Rectangle {
color: "navajowhite"
anchors.fill: parent
anchors.leftMargin: 10
}
}
}

As mentioned by @folibis, you can also use Canvas, for which there is already a similar answer.



Related Topics



Leave a reply



Submit