PDA

View Full Version : Move toplevelwidget over border of multiscreen desktop



olzzen
15th March 2016, 12:23
Hi folks,

hope somebody can guide me...

In my application i have a QMainWindow with a central widget. Now what i want is to place a parentless (toplevel) QWidget over the existing central widget which acts like an event-proxy. That's no problem as it is not difficult.

The problem comes up when using the application within a multiscreen desktop environment. When the application overlaps a screen so that parts of the mainwindow are drawn on another screen, the correct placement of the event-proxy-widget fails, although i move the event-proxy-widget in global coordinates.

How can i freely move a widget within multiple screens, including the case where the widget overlaps screen-borders?

Thanks in advance
olzzen

olzzen
24th November 2017, 07:19
Just to share the solution for the described problem...

I don't know if its a Qt or X11 bug but the solution is to show the widget before moving :cool:

d_stranz
24th November 2017, 19:05
It's not a bug, it's a feature ;)

Qt widgets and their contents do not have correct geometry until their showEvent() occurs. So, in the constructor as well as in the resizeEvent() calls that occur prior to the showEvent(), any calls to methods that retrieve geometry (sizes, positions, etc.) will typically not return correct results.

Qt's layout engine may generate resizeEvents() prior to a showEvent() as it calculates sizes and positions for the contents of the widgets it is laying out. This isn't a bug, it is by design. The way you avoid errors based on incorrect geometry is to ensure that you don't do anything until QWidget::isVisible() returns true.

Ginsengelf
28th November 2017, 09:38
Hi, you could use event filtering with a QObject QObject::installEventFilter instead of your proxy widget. That way you don't have to care about coordinates of a widget and you can access all the events of the central widget.

Ginsengelf