PDA

View Full Version : how to select the default screen for an application to run in? multi-head screen



goldmanasia
20th January 2011, 02:18
(i guess this is a newbie question, thus move it to this forum.)
hi,

i have a external screen with my laptop in extension mode:
screen 1: laptop's native onescreen 2: external one
screen 2 is configured as the main display in windows 7 setup.
in my qt apps, when running it, it always starts in the main display (screen 2). is there any way to set the app to start in screen 1?

i tried the following codes, without working.
QDesktopWidget* desktop = QApplication::desktop();QWidget *screenWidget = desktop->screen(2);

thanks a lot.

ChrisW67
20th January 2011, 04:15
The QDesktopWidget only gives you information on the screens available. If you query for the QRect of the second screen with QDesktopWidget::screenGeometry() and then use QWidget::move() on your main window to put it within that geometry does that work?

Another observation; the screens are almost certainly numbered from 0, so your second screen's index will be 1 not 2. Further, if Windows is treating your two screens as one virtual desktop you may only get one screen out of QDesktopWidget.

goldmanasia
25th January 2011, 10:19
Thank you ChirisW67.
I will try it later on. Currently have to work on some more urgent issues.

Thanks for the help.

Lesiok
25th January 2011, 13:36
This code opens new window in selected screen :

int screen_number = 2;//2 is an example, this is 3th screen, because screens are numbered from 0
MyWidget *my_widget;
QWidget *parent_screen = 0x00;
bool is_virtual_desktop = QApplication::desktop()->isVirtualDesktop();
QPoint bottom_left = QApplication::desktop()->screenGeometry(0).bottomLeft();

if( is_virtual_desktop )
bottom_left = QApplication::desktop()->screenGeometry(screen_number).bottomLeft();
else
parentScreen = QApplication::desktop()->screen(screen_number);

my_widget = new MyWidget(parentScreen);
if( is_virtual_desktop )
my_widget->move( bottom_left );