Results 1 to 8 of 8

Thread: Problem with screen index

  1. #1
    Join Date
    Jan 2011
    Posts
    19
    Thanks
    4

    Default Problem with screen index

    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 :
    Qt Code:
    1. QDesktopWidget monEcran;
    2. cout << "nbre: " << monEcran.screenCount()<<endl;
    3. int screenIndex = monEcran.screenNumber(this);
    4. LargeurFen=monEcran.screenGeometry(screenIndex ).width();
    5. hauteurFen=monEcran.screenGeometry(screenIndex ).height();
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Problem with screen index

    Where do you call that code? Is it called before anything of the application is shown? If so, that's probably the problem.

  3. #3
    Join Date
    Jan 2011
    Posts
    19
    Thanks
    4

    Default Re: Problem with screen index

    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,

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Problem with screen index

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

  5. #5
    Join Date
    Jan 2011
    Posts
    19
    Thanks
    4

    Default Re: Problem with screen index

    On the main.cpp, i tryied :

    Qt Code:
    1. CZoneDessin fen(0, 0);
    2. fen.show();
    3. cout << endl << "scr : " << testWD.screenNumber(&fen) << endl;
    To copy to clipboard, switch view to plain text mode 

    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,

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Problem with screen index

    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
    Qt Code:
    1. QDesktopWidget testWD=QApplication::desktop();
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2011
    Posts
    19
    Thanks
    4

    Default Re: Problem with screen index

    Hi,
    Qt Code:
    1. QApplication::processEvents();
    2. QDesktopWidget *testWD = QApplication::desktop();
    3. cout << endl << "scr : " << testWD->screenNumber(this) << endl;
    To copy to clipboard, switch view to plain text mode 

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

  8. #8
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: Problem with screen index

    Try this:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. this->test();
    5. }
    6.  
    7. MainWindow::~MainWindow()
    8. {
    9. this->test();
    10. }
    11.  
    12. void MainWindow::test( void )
    13. {
    14. qDebug() << QApplication::desktop()->screenNumber( this );
    15. }
    To copy to clipboard, switch view to plain text mode 
    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.

Similar Threads

  1. Index out of range problem for a xml file
    By Niamita in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2011, 08:11
  2. ComboBox Completer Index Problem
    By majatu in forum Qt Programming
    Replies: 3
    Last Post: 7th June 2009, 15:30
  3. QList index out of range problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2008, 09:40
  4. Available Screen Problem
    By December in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2007, 17:01
  5. Problem with index in a QTreeView
    By hubert_p in forum Qt Programming
    Replies: 4
    Last Post: 22nd October 2006, 16:54

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
  •  
Qt is a trademark of The Qt Company.