Is there a knows bug with QApplication::desktop()->screenNumber(this) reporting the wrong screen?



  • I've got a bit of an odd setup with 3 different sized monitors in my work configuration. But I've noticed what appears to be a bug in the Qt desktop screen code.
    When my mainwindow is initially shown on one of the secondary screens.
    qApp->desktop()->screenNumber(this) will still return 0 for the main screen even though the window is on one of the other two screens. Of cause giving the screenNumber call a QPoint will give the correct screen number.

        auto globalCenter = this->mapToGlobal(this->geometry().center());
        screenIdx = qApp->desktop()->screenNumber(globalCenter);
    

    So this is a possible workaround. But calling showFullScreen will incorrectly show the mainwindow in full screen mode on screen 0 effectively moving the window to another monitor in this case. I've had to resort to this kind of hackery to get around this issue:

    void MainWindow::toggleFullscreen()
    {
        // ensure winow is on the correct screen before going full screen
        auto screenIdx = mApp().desktop()->screenNumber(this);
        if (screenIdx >= 0 && screenIdx < QGuiApplication::screens().count()) {
    	auto* screen = QGuiApplication::screens()[screenIdx];
    
    	if (screen && windowHandle()->screen() != screen)
    	  windowHandle()->setScreen(screen);
        }
        ...
    

    Is this a previously known error or am I missing something here?


  • Moderators

    Are you aware of Qt's bug tracking system JIRA?
    There you can check also for bugs.



  • @koahnig I did search the Qt bug tracking system before. But it's huge and I'm probably not creative enough to come up with fitting search terms as I can't find anything on this. Just hoping someone else have run into this before and can confirm it's a Qt bug and not me.


  • Moderators

    I know this problem. ;)
    I have never found an index in a book stating "the solution to your problem is on page xx".
    Add a tag to multi-screen. There is also another post to a bug, but probably unrelated.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.