QApplication primary screen changed
-
Hi guys,
before I used QApplication::desktop() which returned QWidget object. That was nice. But now I'm migrating to Qt 5.15.2 there recomended use QScreen objects.
But I'm not completly understanding relations between QApplication object and QScreen objects. So, how can I get current QScreen for my QApplication?
P.S. For QWidget has method QWidget::screen(). Ok.Thanks a lot.
-
@Alexey-Serebryakov said in QApplication primary screen changed:
QGuiApplication::primaryScreenChanged
In Windows the primary screen is the one showing the full task bar. The changed signal will only be emitted when you change the primary screen in your Windows settings. It is not related to moving the widget from one screen to the other.
-
QApplication does not correspond to anything visible. The desktop() method used to report something that might correspond to a physical screen: it was a best guess that was good enough before multiple monitors became routine.
Your application's top-level window (or windows) may appear on any (or multiple) of the screens available to a system. It therefore makes more sense to talk about the screen on which each of these widgets appear. You get the screen that your application main GUI widget(s) appear on by calling QWidget::screen() on the main window object. You can find information about the screen's actual geometry, and relationships to other screens, from the returned QScreen object.
-
@ChrisW67 so, I have QApplication. And I have popup notification widget showing in the bottom right corner of screen. I need show popup widget on the same screen where showing currently main application window.
Thank you. -
@Alexey-Serebryakov
You should be able to find your main widget using QApplication::topLevelWidgets()
Then you can get the screen using QWidget::screen()Or so I would imagine.
-
@Asperamanca Ok/ And then? Before I used QDesktopWidget class but now that is obsolete and recomended use QScreen and so on. But QScreen not derived from QWidget. How can I show widget on screen specified? For example I have popup notification widget in my application and I want show that on screen specified. That mean the QDesktopWidget object was parent for my popup widget. But now my popup widget shows only on primary display. :-(
-
@Alexey-Serebryakov said in QApplication current screen:
does not work
Such statements are really not helpful.
In what way it "does not work"?
Does the connection fail (please use new connect sintax instead of the old one you're using now)!
Does the connection succeed but the slot is not called? -
@jsulm yeah connection succeed but the slot is not called.
connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &DefaultNotification::OnScreenChanged); ... void DefaultNotification::OnScreenChanged(QScreen *screen) { currentScreen_ = screen; qInfo() << "Screen was changed to " << screen->name(); }
Hmm... when this slot must me called? When I move main window to another screen?
-
@Alexey-Serebryakov said in QApplication current screen:
How can I show widget on screen specified?
-
-
@Alexey-Serebryakov said in QApplication primary screen changed:
QGuiApplication::primaryScreenChanged
In Windows the primary screen is the one showing the full task bar. The changed signal will only be emitted when you change the primary screen in your Windows settings. It is not related to moving the widget from one screen to the other.