Results 1 to 4 of 4

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

  1. #1
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default how to select the default screen for an application to run in? multi-head screen

    (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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to select the default screen for an application to run in? multi-head screen

    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.

  3. #3
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to select the default screen for an application to run in? multi-head screen

    Thank you ChirisW67.
    I will try it later on. Currently have to work on some more urgent issues.

    Thanks for the help.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to select the default screen for an application to run in? multi-head screen

    This code opens new window in selected screen :
    Qt Code:
    1. int screen_number = 2;//2 is an example, this is 3th screen, because screens are numbered from 0
    2. MyWidget *my_widget;
    3. QWidget *parent_screen = 0x00;
    4. bool is_virtual_desktop = QApplication::desktop()->isVirtualDesktop();
    5. QPoint bottom_left = QApplication::desktop()->screenGeometry(0).bottomLeft();
    6.  
    7. if( is_virtual_desktop )
    8. bottom_left = QApplication::desktop()->screenGeometry(screen_number).bottomLeft();
    9. else
    10. parentScreen = QApplication::desktop()->screen(screen_number);
    11.  
    12. my_widget = new MyWidget(parentScreen);
    13. if( is_virtual_desktop )
    14. my_widget->move( bottom_left );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 0
    Last Post: 19th January 2011, 04:29
  2. application screen as screen saver
    By wizarda in forum Qt Programming
    Replies: 0
    Last Post: 6th January 2011, 20:15
  3. How to detect multi screen in QT?
    By Kevin Hoang in forum Qt Programming
    Replies: 9
    Last Post: 27th March 2010, 00:02
  4. Display a QWidget using multi-screen
    By tarod in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 15:02
  5. multi screen
    By Thomas Feldman in forum Qt Programming
    Replies: 5
    Last Post: 9th May 2007, 17:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.