PDA

View Full Version : Transparent area inside semi transparent area.



m.m
13th February 2015, 16:27
Hi Community,

I'm new to Qt and already have a pretty decent task to solve.

I want to implement screen capture functionality. To capture a part of the screen the user can enter selection mode.
In selection mode, I want to show a semi-transparent layer expanding over all screens and a fully transparent rectangular layer inside which can be resized and moved.
The later one indicates the selected area. All windows on the desktop should visually appear below these two layers. That is they are semi-transparent if not inside the selection area. However interaction with those windows should be possible, that is they can e.g. be moved and resized.

How can I archive that behavior? Any help/code snippets are highly appreciated.

I'm using the latest Qt version under Windows.

m.m
14th February 2015, 01:36
Can anyone point me in the right direction, please.

I know how to create a fullscreen semi-transparent window on top.
How can I place a moveable resizable widget with full transparency inside it?
How can I still access the application windows below them?

anda_skoa
14th February 2015, 09:23
One way to have a "hole" in a window is to paint its content using a QPainterPath which has two rectangles: the one for the full size and the hole.
Using a semi transparent color to fill that path will only apply that color to the intersection of the two rectangles.

Something like this


void MyWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);

QPainterPath path;
path.addRect(rect());
path.addRect(m_holeRect);
painter.fillPath(path, semiTransparentColor);
}


As for interacting with windows below your window, that is out of scope for the application. You'll need to consult operating system documentation for that whether it is possible at all and if so, how to do that.

Cheers,
_