QT - How to know if the widget changed screens? Is there a signal?

232 Views Asked by At

I'm still a beginner at Qt (5.15.2) and I'm trying to implement a way to setMaximumWidth of the application MainWindow based on the current screen it's on.

For example: if the application is on screen 1 (1366x768) it should have maximumWidth of 1366, if it goes to screen 2 (1920x1080), then it should have maximumWidth of 1920, and the same logic applies to a N number of screens. Is there a signal that can help me with this? If there is not, is there a good way to simulate a screen change signal?

What I tried:

  1. I've searched for a QScreen::screenChanged signal but I couldn't find one, so I assume it doesn't exist.

  2. I've tried using QGuiApplication::primaryScreenChanged(), but it didn't work because it only works with primary screens, so when I merely change screens the signal doesn't get activated, only if I go to windows and change the primary screen to the one I'm currently on (which is not desirable).

  3. I've also thought of using timeout signal that would activate a function that checks the current screen and sets the maximum width, it probably would work, but it doesn't seem like a good solution performance wise.

Edit: as for what would cause the screen change, it would be the user, either by dragging the window to another screen or using shortcut keys.

0

There are 0 best solutions below