Results 1 to 4 of 4

Thread: Display a QWidget using multi-screen

  1. #1
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Display a QWidget using multi-screen

    Hello,

    I've got two monitors in Linux configured as multi-screen, so I've two monitors connected to one graphic card. I'm trying to display a QWidget on upper or lower monitor using QDesktopWidget, but I'm doing something wrong because I can't do it.

    I leave some code below to understand better my issue:

    The class inherits QWidget:

    Qt Code:
    1. IFHMIQtGui(QWidget* parent, GUIDevice device)
    To copy to clipboard, switch view to plain text mode 

    The constructor:

    Qt Code:
    1. IFHMIQtGui::IFHMIQtGui(QWidget* parent, GUIDevice device)
    2. {
    3. QDesktopWidget pDesktop;
    4. QWidget *qscreen;
    5.  
    6. if (device == DEVICE_UPPER)
    7. {
    8. qscreen = pDesktop.screen(1);
    9. }
    10. else if (device == DEVICE_LOWER)
    11. {
    12. qscreen = pDesktop.screen(0);
    13. }
    14.  
    15. QWidget(qscreen);
    16. }
    To copy to clipboard, switch view to plain text mode 

    I know that if I pass the QDesktopWidget to my IFHMIQtGui when I contruct the object, the QWidget is displayed on the right monitor. Anyway, the problem is that I need to use QDesktopWidget inside the IFHMIQtGui constructor.

    Thank you.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Display a QWidget using multi-screen

    Qt Code:
    1. QDesktopWidget *pDesktop = QApplication::desktop();
    2. QRect geometry = pDesktop->availableScreenGeometry(number);
    3. move(geometry.topLeft());
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display a QWidget using multi-screen

    Quote Originally Posted by jpn View Post
    Qt Code:
    1. QDesktopWidget *pDesktop = QApplication::desktop();
    2. QRect geometry = pDesktop->availableScreenGeometry(number);
    3. move(geometry.topLeft());
    To copy to clipboard, switch view to plain text mode 
    I put that code in the constructor, but the QWidget is always displayed on the lowermonitor. I've also changed the "number" variable without success.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Display a QWidget using multi-screen

    Please read: Restoring a Window's Geometry:
    On Windows, this is basically storing the result of QWidget::geometry() and calling QWidget::setGeometry() in the next session before calling show(). On X11, this won't work because an invisible window doesn't have a frame yet. The window manager will decorate the window later. When this happens, the window shifts towards the bottom/right corner of the screen depending on the size of the decoration frame. Although X provides a way to avoid this shift, most window managers fail to implement this feature.

    A workaround is to call setGeometry() after show().
    Maybe you are experiencing this problem?
    J-P Nurmi

Similar Threads

  1. Setting manually cursor position on multi screen systems
    By irreriwan in forum Qt Programming
    Replies: 0
    Last Post: 4th March 2008, 09:47
  2. multi screen
    By Thomas Feldman in forum Qt Programming
    Replies: 5
    Last Post: 9th May 2007, 16:41
  3. Replies: 3
    Last Post: 8th March 2007, 14:54
  4. QWidget display on 2 stack widget page
    By spawnwj in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2006, 12:07
  5. how to display a window full screen??
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 8th May 2006, 12:07

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.