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. QApplication primary screen changed
Forum Updated to NodeBB v4.3 + New Features

QApplication primary screen changed

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 6 Posters 2.8k Views 3 Watching
  • 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.
  • C ChrisW67

    QApplication does not correspond to anything visible. The desktop() method used to report something that might correspond to a physical screen: it was a best guess that was good enough before multiple monitors became routine.

    Your application's top-level window (or windows) may appear on any (or multiple) of the screens available to a system. It therefore makes more sense to talk about the screen on which each of these widgets appear. You get the screen that your application main GUI widget(s) appear on by calling QWidget::screen() on the main window object. You can find information about the screen's actual geometry, and relationships to other screens, from the returned QScreen object.

    A Offline
    A Offline
    Alexey Serebryakov
    wrote on last edited by
    #4

    @ChrisW67 but how can show QWidget on the screen specified?

    1 Reply Last reply
    0
    • C ChrisW67

      QApplication does not correspond to anything visible. The desktop() method used to report something that might correspond to a physical screen: it was a best guess that was good enough before multiple monitors became routine.

      Your application's top-level window (or windows) may appear on any (or multiple) of the screens available to a system. It therefore makes more sense to talk about the screen on which each of these widgets appear. You get the screen that your application main GUI widget(s) appear on by calling QWidget::screen() on the main window object. You can find information about the screen's actual geometry, and relationships to other screens, from the returned QScreen object.

      A Offline
      A Offline
      Alexey Serebryakov
      wrote on last edited by
      #5

      @ChrisW67 so, I have QApplication. And I have popup notification widget showing in the bottom right corner of screen. I need show popup widget on the same screen where showing currently main application window.
      Thank you.

      1 Reply Last reply
      0
      • C ChrisW67

        QApplication does not correspond to anything visible. The desktop() method used to report something that might correspond to a physical screen: it was a best guess that was good enough before multiple monitors became routine.

        Your application's top-level window (or windows) may appear on any (or multiple) of the screens available to a system. It therefore makes more sense to talk about the screen on which each of these widgets appear. You get the screen that your application main GUI widget(s) appear on by calling QWidget::screen() on the main window object. You can find information about the screen's actual geometry, and relationships to other screens, from the returned QScreen object.

        A Offline
        A Offline
        Alexey Serebryakov
        wrote on last edited by
        #6

        @ChrisW67 Also QDesktopWidget class is obsolete. :-( That why I'm using QScreen, but QScreen does not derived from QWidget. :-((

        A 1 Reply Last reply
        0
        • A Alexey Serebryakov

          @ChrisW67 Also QDesktopWidget class is obsolete. :-( That why I'm using QScreen, but QScreen does not derived from QWidget. :-((

          A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #7

          @Alexey-Serebryakov
          You should be able to find your main widget using QApplication::topLevelWidgets()
          Then you can get the screen using QWidget::screen()

          Or so I would imagine.

          A 1 Reply Last reply
          0
          • A Asperamanca

            @Alexey-Serebryakov
            You should be able to find your main widget using QApplication::topLevelWidgets()
            Then you can get the screen using QWidget::screen()

            Or so I would imagine.

            A Offline
            A Offline
            Alexey Serebryakov
            wrote on last edited by Alexey Serebryakov
            #8

            @Asperamanca Ok/ And then? Before I used QDesktopWidget class but now that is obsolete and recomended use QScreen and so on. But QScreen not derived from QWidget. How can I show widget on screen specified? For example I have popup notification widget in my application and I want show that on screen specified. That mean the QDesktopWidget object was parent for my popup widget. But now my popup widget shows only on primary display. :-(

            jsulmJ 1 Reply Last reply
            0
            • A Alexey Serebryakov

              @ChrisW67 also

              connect(qGuiApp, SIGNAL(primaryScreenChanged(QScreen*)), this, SLOT(OnScreenChanged(QScreent*)));
              

              does not work. :-((

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #9

              @Alexey-Serebryakov said in QApplication current screen:

              does not work

              Such statements are really not helpful.
              In what way it "does not work"?
              Does the connection fail (please use new connect sintax instead of the old one you're using now)!
              Does the connection succeed but the slot is not called?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Alexey-Serebryakov said in QApplication current screen:

                does not work

                Such statements are really not helpful.
                In what way it "does not work"?
                Does the connection fail (please use new connect sintax instead of the old one you're using now)!
                Does the connection succeed but the slot is not called?

                A Offline
                A Offline
                Alexey Serebryakov
                wrote on last edited by Alexey Serebryakov
                #10

                @jsulm yeah connection succeed but the slot is not called.

                connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &DefaultNotification::OnScreenChanged);
                ...
                void DefaultNotification::OnScreenChanged(QScreen *screen) {
                    currentScreen_ = screen;
                    qInfo() << "Screen was changed to " << screen->name();
                }
                

                Hmm... when this slot must me called? When I move main window to another screen?

                S 1 Reply Last reply
                0
                • A Alexey Serebryakov

                  @Asperamanca Ok/ And then? Before I used QDesktopWidget class but now that is obsolete and recomended use QScreen and so on. But QScreen not derived from QWidget. How can I show widget on screen specified? For example I have popup notification widget in my application and I want show that on screen specified. That mean the QDesktopWidget object was parent for my popup widget. But now my popup widget shows only on primary display. :-(

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  @Alexey-Serebryakov said in QApplication current screen:

                  How can I show widget on screen specified?

                  https://doc.qt.io/qt-6/qwidget.html#setScreen

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @Alexey-Serebryakov said in QApplication current screen:

                    How can I show widget on screen specified?

                    https://doc.qt.io/qt-6/qwidget.html#setScreen

                    A Offline
                    A Offline
                    Alexey Serebryakov
                    wrote on last edited by
                    #12

                    @jsulm super! But I'm using Qt 5.15.2. :-((

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      zeljko
                      wrote on last edited by
                      #13

                      https://doc.qt.io/qt-5.15/qwindow.html#setScreen

                      1 Reply Last reply
                      0
                      • A Alexey Serebryakov

                        @jsulm yeah connection succeed but the slot is not called.

                        connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &DefaultNotification::OnScreenChanged);
                        ...
                        void DefaultNotification::OnScreenChanged(QScreen *screen) {
                            currentScreen_ = screen;
                            qInfo() << "Screen was changed to " << screen->name();
                        }
                        

                        Hmm... when this slot must me called? When I move main window to another screen?

                        S Offline
                        S Offline
                        SimonSchroeder
                        wrote on last edited by
                        #14

                        @Alexey-Serebryakov said in QApplication primary screen changed:

                        QGuiApplication::primaryScreenChanged

                        In Windows the primary screen is the one showing the full task bar. The changed signal will only be emitted when you change the primary screen in your Windows settings. It is not related to moving the widget from one screen to the other.

                        1 Reply Last reply
                        1

                        • Login

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