Transparent window has different behavior between Linux platform and Windows platform?
-
Hi,
I have an application which have a mainwindow and a dialog, I need part of the dialog become transparent so I can click the mainwindow through the transparent part. I test it on Windows, it works fine, but after running on Linux, the dialog can only see the mainwindow through the transparent part of the dialog, but I can not click the mainwindow through the transparent part. on Windows, I can trigger the click event through the transparent part.
to implement the transparent , I write the following code in my dialog constructor:
setWindowFlags(windowFlags() | Qt::FramelessWindowHint); setAttribute(Qt::WA_TranslucentBackground, true);
and in the .ui file , I have set stylesheet
QWidget {background-color:transparent}
I am using Qt5.12, Windows 10 and Ubuntu 18
Thank you
-
@Mozzie said in Transparent window has different behavior between Linux platform and Windows platform?:
I can trigger the click event through the transparent part
Please show how you're doing this. It should work same way on Linux.
-
Hi,
such as I have a button on my mainwindow, and is the dialog is not transparent , the button will be cover up. but after make it transparent , on Windows I can click it by the left mouse button, on Linux, I can not.I override the mouse event of main window and dialog, on Windows, if I click the transparent part of the dialog, the even will get into QMainWindow::mouseXXXEvent, but on Linux if I click the transparent part of the dialog, the even will get into QDialog::mouseXXXEvent, if I change the dialog to a widge, the problem still.
Thank you
-
@Mozzie said in Transparent window has different behavior between Linux platform and Windows platform?:
but after make it transparent , on Windows I can click it by the left mouse button
I'm surprised this works.
Transparency actually means the the widget is visually transparent, not that it is "transparent" for the mouse. -
on Windows, this could work, I dont know why. so visually transparent should be the default behavior?
is there any way to transfer event from transparent part not all the event of the dialog to the widget belong to the mainwindow.
I only knowinstallEventFilter
andQApplication::posEvent
but it seems its very complex to because I have to check the transparency of that point and find which widget is under that point.Thank you
-
Maybe tweaking with this widget attribute:
Qt::WA_TransparentForMouseEvents 51
When enabled, this attribute disables the delivery of mouse events to the widget and its children. Mouse events are delivered to other widgets as if the widget and its children were not present in the widget hierarchy; mouse clicks and other events effectively "pass through" them. This attribute is disabled by default. -
Thank you.
When enabled, this attribute disables the delivery of mouse events to the widget and its children.
This might be not suitable, because there is some part of the dialog is not transparent still need receive the mouse event, but this attribute will "pass through" all of the child widgets?
-
Qt has a feature for this, i.e. masking of widgets. Have a look at their shaped clock example: https://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html