Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Start program center screen on main monitor
Hi, i have in computer two monitors... and when i use this code:
@map_selection_menu->move(QApplication::desktop()->availableGeometry(0).width() + 1, map_selection_menu->y());@
It start between two monitors... and i need to start it in center or main monitor...better will be when program detect all monitors and after calculate to main...
I have for screens connected:
@if (QApplication::desktop()->screenCount() > 1)
QRect geom = QApplication::desktop()->screenGeometry(0);
But now i dont know what with "if" ... how i can continue?
have you tried this:
This should move your widget to the center of the primary screen.
move to left top on main screen
Guest last edited by
then get your resolution and place your widget at width/2, height/2
have you tried it? I did it with move(0,0) and it was in center of the screen. See "this code":http://developer.qt.nokia.com/forums/viewthread/10075/.
Is your widget the main window or a child widget? Because child widgets are always at center of parent widget per default. And I think main window is at center of primary screen per default.
Does QWidget::move(int x, int y) move to position x,y or does it move to a position that is x further left or right and y further up or down ? The later would explain why move(0,0) put my splashscreen to center (because it was allready at center and was moved 0 further right and 0 further up).
It isnt main window just QWidget.And i say move( 0, 0 ) dont help
Does your widget have a parent ?
QSize screenSize = QApplication::desktop()->geometry().size();
int primaryScreenWidth = screenSize.width();
int primaryScreeHeight= screenSize.height();
int widgetWidth = yourWidget.width();
int widgetHeight= yourWidget.height();
yourWidget->move(primaryScreenWidth/2 - widgetWidth/2, primaryScreeHeight/2 - widgetHeight/2)
I cant call
@QSize screenSize = QApplication::desktop()->geometry().size();@
No suitable convert from QDesktopWidget* to QSize
andre last edited by
This is not the method you are after. Read the section Screen Geometry in the [[doc:QDesktopWidget]] documentation.