Important: Please read the Qt Code of Conduct -

Show application on multiple displays

  • Hello,

    I'm doing some attempts to show application on all available screens. I'm using 3 test systems:
    Windows 10, Qt 5.9.9
    Ubuntu 18.04, native installation, Qt 5.9.7
    Ubuntu 18.04, virtual machine, Qt 5.9.7
    All test systems are equipped with 2xFullHD displays, same resolution and aspect ratio.

    I found a lot of information how to use all displays. Currently i'm using one window in full screen mode.
    Here is main function:

    #include "mainwindow.h"
    #include <QApplication>
    #include <QDesktopWidget>
    #include <QDebug>
    int displayXsize, displayYsize;
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MainWindow w;
        displayXsize = QApplication::desktop()->geometry().width();
        displayYsize = QApplication::desktop()->geometry().height();
        qDebug().nospace() << "Display size: " << displayXsize << "x" << displayYsize;
        w.setGeometry(0,0,displayXsize, displayYsize);
        qDebug().nospace() << "Window size: " << w.width() << "x" << w.height();
        return a.exec();

    Once application is started, display size is calculated correctly and main window width and height are as expected - 3840x1080 on all test systems.
    On Windows 10, main window is shown on all displays. It starts from display 0 and continues on display 1.
    On Ubuntu, native installation and VM, main window is shown only on display 0.

    I've made attempt to manually set the width of main window.
    In Windows, once main window size becomes bigger than display 0, main window is extended on display 1.
    In Ubuntu once main window size becomes bigger than display 0, right border of main window is aligned to right side of display 0 but it's not extended on display 1.

    Is there a way to extend the main window on Ubuntu?

    Thank you!

  • Hello,

    I've made some experiments with order of

    w.setGeometry(0,0,displayXsize, displayYsize);

    Unfortunately the result in Ubuntu is the same - main window is on display 0 only.

    I've added push button in main window. Once button is pressed, current main window width is printed and increased with 100 pixels. Here is the result:

    Display size: 3840x1080   // main function, size of QApplication::desktop()->geometry()
    Window size: 3840x1080    // main function, size of main window after w.setGeometry()
                                          // main function a.exec()
    Current main window size: 1920x1080   // Button is pressed
    New main window size: 2020x1080       // New size of main window is set
    Current main window size: 2020x1080   // Button is pressed
    New main window size: 2120x1080       // New size of main window is set

    Looks like after a.exec main window size is set to size of display 0. Once button is pressed, new size of main window is set, it's wider than display 0 width and main window is extended on display 1.

    Looks like resizing of main window alter a.exec() will solve my problems, but is this the correct way?


  • Hello,

    Looks like I found a solution for Windows and Ubuntu.
    All of the code is the same as first post, but main window geometry and position is set in different way:

            w.setFixedSize(displayXsize, displayYsize);

    I will continue digging tomorrow to find a way to avoid moving main window start position to fixed display corner.
    currently display 0 shall be left one, display 1 shall be right one.

Log in to reply