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. Detecting the removal of a screen and modifying the app accordingly.
QtWS25 Last Chance

Detecting the removal of a screen and modifying the app accordingly.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qguiapplicationqdesktopwidgetresponsive
6 Posts 4 Posters 2.3k 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
    MrCrackPotBuilder
    wrote on 13 Sept 2018, 06:34 last edited by
    #1

    So far I have an application that counts how many screens are available.

    QDesktopWidget *widget = QApplication::desktop();
    qDebug() << 'Number of screens:' << widget->screenCount();
    
    if (widget->screenCount() > 1) {
        leftScreen.show();
        rightScreen.show();
        singleScreen.close();
    } else if (widget->screenCount() == 1){
        leftScreen.close();
        rightScreen.close();
        singleScreen.show();
    }
    
    

    This will debug how many screens to console and if more than 1 the 2 screens are shown and if only one then the one screen.

    If i remove a screen though nothing else changes but if i close the application and then open it again the single ui will display.

    QGuiApplication has a member called screenRemoved but im struggling to figure out how to incorporate that into my application.

    Later i will tell each screen to go to its set place but that is pretty straight forward.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 13 Sept 2018, 07:27 last edited by
      #2

      You can listen to screenCountChanged() signal to know when the count changes.

      (Z(:^

      1 Reply Last reply
      1
      • M Offline
        M Offline
        MrCrackPotBuilder
        wrote on 13 Sept 2018, 07:50 last edited by
        #3

        Thanks although what arguments do i put in? The docs don't really mention much.

        Its also saying the same as before so I.m definitely going to have to use the QGuiApplication but how that i cant figure out... Yet

        M J 2 Replies Last reply 13 Sept 2018, 07:52
        0
        • M MrCrackPotBuilder
          13 Sept 2018, 07:50

          Thanks although what arguments do i put in? The docs don't really mention much.

          Its also saying the same as before so I.m definitely going to have to use the QGuiApplication but how that i cant figure out... Yet

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 13 Sept 2018, 07:52 last edited by
          #4

          @MrCrackPotBuilder
          Hi
          Its a signal so you would connect it up to your own slot and Qt will then call
          this slot when screen count changes.

          1 Reply Last reply
          1
          • M Offline
            M Offline
            MrCrackPotBuilder
            wrote on 13 Sept 2018, 08:01 last edited by MrCrackPotBuilder
            #5

            ah then im going to need to make a new header and source file becuase its all being done in main.cpp

            im taking a wild guess but inside my main i could do

            QQuiApplicationt::connect(&screenRemoved, &displayChange::displayChange);
            
            
            1 Reply Last reply
            0
            • M MrCrackPotBuilder
              13 Sept 2018, 07:50

              Thanks although what arguments do i put in? The docs don't really mention much.

              Its also saying the same as before so I.m definitely going to have to use the QGuiApplication but how that i cant figure out... Yet

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 13 Sept 2018, 08:04 last edited by J.Hilk
              #6

              @MrCrackPotBuilder said in Detecting the removal of a screen and modifying the app accordingly.:

              Its also saying the same as before so I.m definitely going to have to use the QGuiApplication but how that i cant figure out... Yet

              you #include <QGuiApplication> in your class that than allows you access to the (unique) application instance pointer qApp than you can use that to update your Layout.

              QObject::connect(qApp, &QGuiApplication::screenCountChanged,  this,      &myClass::screenCountSlot);
              

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              2

              4/6

              13 Sept 2018, 07:52

              • Login

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