Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there a knows bug with QApplication::desktop()->screenNumber(this) reporting the wrong screen?

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

Scheduled Pinned Locked Moved General and Desktop
windowsqt5multi-screen
4 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikag
    wrote on 27 Jul 2015, 09:26 last edited by koahnig
    #1

    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?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on 27 Jul 2015, 10:38 last edited by
      #2

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

      Vote the answer(s) that helped you to solve your issue(s)

      M 1 Reply Last reply 27 Jul 2015, 13:14
      0
      • K koahnig
        27 Jul 2015, 10:38

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

        M Offline
        M Offline
        mikag
        wrote on 27 Jul 2015, 13:14 last edited by
        #3

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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on 27 Jul 2015, 14:14 last edited by
          #4

          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.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0

          2/4

          27 Jul 2015, 10:38

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved