QGuiApplication::screens() problem



  • I'm working on debian-based OS. There are 2 DVI monitors, but when I call `
    QGuiApplication::screens() it returns a list with only one item.
    I tryed to execute shell commands and that is what I got:

    DISPLAY=:0 xrandr

    Screen 0: minimum 8 x 8, current 1280 x 2048, maximum 32767 x 32767
    DVI1 connected primary 1280x1024+0+1024 (normal left inverted right x axis y axis) 380mm x 300mm
       1280x1024     60.02*+  75.02  
       1280x1024_60.0  60.02  
       1152x864      75.00    59.97  
       1024x768      75.03    70.07    60.00  
       832x624       74.55  
       800x600       72.19    75.00    60.32    56.25  
       640x480       75.00    72.81    66.67    59.94  
       720x400       70.08  
    DVI2 unknown connection 1280x1024+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
       1280x1024     60.02 +
       1280x1024_60.0  60.02* 
    VIRTUAL1 disconnected (normal left inverted right x axis y axis)
    

    DISPLAY=:0 xrandr —listactivemonitors

    0: +*DVI1 1280/380x1024/300+0+1024  DVI1
    1: +DVI2 1280/339x1024/271+0+0  DVI2
    

    Is there a way to fix it?


  • Lifetime Qt Champion

    Hi,

    What version of Qt ?
    What Linux distribution ?



  • @SGaist here it is:
    qmake -v

    QMake version 3.1
    Using Qt version 5.9.7 in /usr/lib
    

    /proc/version

    Linux version 4.14.103 (ubuntu@ole) (gcc version 6.4.0 (GCC)) #1 SMP PREEMPT Sun Mar 17 17:47:26 UTC 2019
    

  • Lifetime Qt Champion

    What is your graphic hardware ?



  • It's because you're using twinview or xinerama. That maps the multiple screens into one virtual desktop under a single DISPLAY variable whos dimensions are the sum of all available monitors. I run multiple monitors, but each one is a separate DISPLAY (:0.0 and :0.1)



  • @Kent-Dorfman no, it is not. If I call QGuiApplication::screens().first()->availableGeometry() I will get a rect matching to one of my screens, not their sum



  • @SGaist I can fetch lspci | grep VGA, is it enough?

    00:02.0 VGA compatible controller: Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller (rev 03)
    


  • from the documention...

    availableVirtualGeometry : const QRect
    
    This property holds the available geometry of the virtual desktop to which this screen belongs
    
    Returns the available geometry of the virtual desktop corresponding to this screen.
    
    This is the union of the virtual siblings' individual available geometries.
    
    Access functions:
    QRect 	availableVirtualGeometry() const
    
    Notifier signal:
    void 	virtualGeometryChanged(const QRect &rect)
    
    See also availableGeometry() and virtualSiblings().
    

    I know X11 quite well. Trust me on this.



  • and...

    QList<QScreen *> QGuiApplication::screens()
    
    Returns a list of all the screens associated with the windowing system the application is connected to.
    

    What happens to your QList<QScreen> if your app has two windows and one window is on each physical display. I bet ya in that case the list has two entries.



  • @Kent-Dorfman I'm not pretending to know X11 well, that's true. But when I executed DISPLAY=:0 xrandr I got two screens associated with on DISPLAY. And when I executed DISPLAY=:0 <path_to_my_app> it recognized only one screen.
    Moreover that, I have forced my app to render a window on the "unexisting" screen and it worked. But all top-level widgets like context menus are drawn on the second ("existing") screen (because they are using global coordinate system I think).



  • @0...-5 said in QGuiApplication::screens() problem:

    @Kent-Dorfman I'm not pretending to know X11 well, that's true. But when I executed DISPLAY=:0 xrandr I got two screens associated with on DISPLAY. And when I executed DISPLAY=:0 <path_to_my_app> it recognized only one screen.
    Moreover that, I have forced my app to render a window on the "unexisting" screen and it worked. But all top-level widgets like context menus are drawn on the second ("existing") screen (because they are using global coordinate system I think).

    Read the definition of screens() closely. You have ONE X11 DISPLAY that spans two distinct monitors and gives you a virtual desktop that is the sum of both physical displays.

    if you open an xterm in each physical display and do echo $DISPLAY you should see the same value returned for each. that means your system is configured for a single large virtual desktop, as is the common config in linux these days. screens() only returns the physical display that contains your running app. If you have a multiwindow app with one window in each monitor, or have a single window that spans both monitors then screens() should return a two entry QList.



  • @Kent-Dorfman I'm sorry, but I steel don't get it...I have two physical monitors each of which is 1280x1024px. If they span into one display I should get a screen with 1280x2048 resolution, shouldn't I? But my screens list contains one an entity with {0, 1024, 1280, 1024} rect for available geometry. I can test what returns availableVirtualGeometry method tomorrow in the office, but no matter it does I can't find a way to render a GUI on the second physical monitor properly.