aram
aram

Reputation: 1444

QInputDialog to appear in the monitor I have focus

I have a 2-monitor setup and when I spawn a QInputDialog it always spawns in the left monitor, ie the one I generally dont use that much. Is there a way to indicate to appear in the monitor I have focus without incurring in any (x,y) positioning stuff.

Basically I dont care where it appears as long as it the monitor with focus.

Upvotes: 1

Views: 151

Answers (1)

Clemens Sielaff
Clemens Sielaff

Reputation: 748

You can use QDesktopWidget (http://doc.qt.io/qt-5/qdesktopwidget.html) to find out which screen your MainWindow is being displayed on. This is going to be the screen with "the focus", I assume.

You then use the screen number to find out the geometry of the screen and place place the QInputDialog in the screen's center - either before the dialog is shown or right afterwards.

I'm afraid this solution is using "(x,y) positioning stuff", but if you find a way to place the dialog without it, let me know.

Upvotes: 1

Related Questions