tags:

views:

37

answers:

2

Hi

I'm writing a program(just for learning purposes, I want to learn C++) in the Qt framework. Is it possible to get how many monitors are connected to my computer and make the program start on different monitor? I want to have an option in the Properties menu where I can tell on which monitor to show the program.

I could not find anything in the Qt developer wiki, maybe you guys can help me with documention on how to do this?

Thanks

+2  A: 

You can use QDesktopWidget to identify how many screens you have attached to your computer and then to retrieve the geometry of each screen:

if (desktopWidget->screenCount() > 1)
{
    QRect geom = desktopWidget->screenGeometry(1);
    // do something useful with this information
}

You may also want to check to see if it's a virtual desktop, but that may not matter to your users.

Kaleb Pederson
+2  A: 

You can get the number of monitors and the total screen size with QDesktopWidget eg.

QDesktopWidget *desktop = QApplication::desktop();
if ( 1==desktop->screenCount()  ) {
    // single monitor - use built in
    showFullScreen();
} else {    
    QRect rect = desktop->screenGeometry(1);
    move(rect.topLeft());
    setWindowState(Qt::WindowFullScreen);       
}
Martin Beckett