PDA

View Full Version : Display a QWidget using multi-screen



tarod
30th June 2008, 07:39
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:


IFHMIQtGui(QWidget* parent, GUIDevice device)

The constructor:



IFHMIQtGui::IFHMIQtGui(QWidget* parent, GUIDevice device)
{
QDesktopWidget pDesktop;
QWidget *qscreen;

if (device == DEVICE_UPPER)
{
qscreen = pDesktop.screen(1);
}
else if (device == DEVICE_LOWER)
{
qscreen = pDesktop.screen(0);
}

QWidget(qscreen);
}


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.

jpn
30th June 2008, 07:47
QDesktopWidget *pDesktop = QApplication::desktop();
QRect geometry = pDesktop->availableScreenGeometry(number);
move(geometry.topLeft());

tarod
30th June 2008, 10:49
QDesktopWidget *pDesktop = QApplication::desktop();
QRect geometry = pDesktop->availableScreenGeometry(number);
move(geometry.topLeft());


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.

jpn
30th June 2008, 14:02
Please read: Restoring a Window's Geometry (http://doc.trolltech.com/4.4/geometry.html#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?