PDA

View Full Version : Problem with screen index



Selven
8th April 2012, 13:26
Hi,

I have a problem with screen index on my Fedora 16.

i'm trying to detect what is the resolution of the current screen, so i do :

QDesktopWidget monEcran;
cout << "nbre: " << monEcran.screenCount()<<endl;
int screenIndex = monEcran.screenNumber(this);
LargeurFen=monEcran.screenGeometry(screenIndex ).width();
hauteurFen=monEcran.screenGeometry(screenIndex ).height();
nbre is the number of screens, and it shows 2 screens. So my second screen is okay.

But the screenindex value is always 0, when i start my program on the first screen, it returns 0, and on the second screen, it returns 0 too...

I don't understand... But if i put manually screenIndex to 1, LargeurFen and hauterFen have the good values, it's the resolution of the second ecran...

I also tryied to do it with a new project, with the basic windows and it's the same issue.

Thanks advance for your help,

ps : sorry for my bad english xD

Lykurg
8th April 2012, 16:06
Where do you call that code? Is it called before anything of the application is shown? If so, that's probably the problem.

Selven
8th April 2012, 18:09
I have a window herited of QDialog and in the constructor, pratically in the end, i put the code i quoted on my precedent post.

Something is shown on the screen, my windows is here, but the cout shows screen ID 0...

Another idea ?

THanks' in advance,

Lykurg
8th April 2012, 18:15
So, I guess it is because the dialog is not shown yet. Try what you get if you use the parent pointer (if not null).

Selven
8th April 2012, 18:28
On the main.cpp, i tryied :


CZoneDessin fen(0, 0);
fen.show();
QDesktopWidget testWD;
cout << endl << "scr : " << testWD.screenNumber(&fen) << endl;

The window is on the first screen, cout value is 0, and i move Qt Creator on the second screen and i launch the application, the window is well on the second screen, and the cout value is always 0.....

What's the fu##### problem, i'm boring with that, i don't understand what i'm doing wrong...

Thanks for your time,

Lykurg
8th April 2012, 19:48
Hi, I currently don't have a dual screen setup and have never worked with it. Two options came to my mind: Call QApplication::processEvents() and see what happens, or/and use
QDesktopWidget testWD=QApplication::desktop();

Selven
8th April 2012, 20:31
Hi,

QApplication::processEvents();
QDesktopWidget *testWD = QApplication::desktop();
cout << endl << "scr : " << testWD->screenNumber(this) << endl;

Always return 0 on each screen...

But thanks a lot for your help, you are the only person who help me and i want to thank you ^^...

Spitfire
9th April 2012, 16:12
Try this:


MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->test();
}

MainWindow::~MainWindow()
{
this->test();
}

void MainWindow::test( void )
{
qDebug() << QApplication::desktop()->screenNumber( this );
}

Start the app, move it to second screen and then close it.
You should get '0' then '1'.

To get proper screen in constructor use move() before calling screenNumber().

All above is true for windows, I haven't checked linux but it may be little different as x11 is asynchronous.