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. Single Qt Application With multiple windows/Widgets on two screens machine.
Forum Updated to NodeBB v4.3 + New Features

Single Qt Application With multiple windows/Widgets on two screens machine.

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 3.7k Views 1 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.
  • IamSumit2I Offline
    IamSumit2I Offline
    IamSumit2
    wrote on last edited by
    #1

    Hi,
    I am creating an application which shows two widgets. I want to show one screen on my first screen and another on second screen.I want to manage my widgets on both screens.

    Thanks.

    Taz742T 2 Replies Last reply
    0
    • W Offline
      W Offline
      wrosecrans
      wrote on last edited by
      #2

      Cool. Are you having some trouble with it that you'd like help with, or just kind of making an announcement?

      1 Reply Last reply
      0
      • IamSumit2I IamSumit2

        Hi,
        I am creating an application which shows two widgets. I want to show one screen on my first screen and another on second screen.I want to manage my widgets on both screens.

        Thanks.

        Taz742T Offline
        Taz742T Offline
        Taz742
        wrote on last edited by Taz742
        #3

        @IamSumit2 said in Single Qt Application With multiple windows/Widgets on two screens machine.:

        I want to show one screen on my first screen

        Sorry, screen is a monitor? You have two monitor and you want to show first widget in the first monitor and second widget to the second monitor?

        Do what you want.

        1 Reply Last reply
        0
        • IamSumit2I IamSumit2

          Hi,
          I am creating an application which shows two widgets. I want to show one screen on my first screen and another on second screen.I want to manage my widgets on both screens.

          Thanks.

          Taz742T Offline
          Taz742T Offline
          Taz742
          wrote on last edited by Taz742
          #4

          @IamSumit2
          If your question is clear for me:

          QDesktopWidget* m = QApplication::desktop();	
          ScndMonitor *scndmon = new ScndMonitor(this); //Your widget, which you want to show second monitor.
          connect(m, &QDesktopWidget::screenCountChanged, this, [=](int count) {
              if (count <= 1) {
                  scndmon->deleteLater();
              }
          }); //If second monitor shut downed delete this.
          
          QRect desk_rect = m->screenGeometry(1); // it is a second monitor
          int desk_x = desk_rect.width();
          int desk_y = desk_rect.height();
          int x = scndmon->width();
          int y = scndmon->height();
          scndmon->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
          scndmon->showFullScreen();
          

          http://doc.qt.io/archives/qt-4.8/qdesktopwidget.html

          Do what you want.

          1 Reply Last reply
          0
          • IamSumit2I Offline
            IamSumit2I Offline
            IamSumit2
            wrote on last edited by
            #5

            @Taz742 said in Single Qt Application With multiple windows/Widgets on two screens machine.:

            @IamSumit2 said in Single Qt Application With multiple windows/Widgets on two screens machine.:

            I want to show one screen on my first screen

            Sorry, screen is a monitor? You have two monitor and you want to show first widget in the first monitor and second widget to the second monitor?

            Yes this was my Question.

            Taz742T 1 Reply Last reply
            0
            • IamSumit2I IamSumit2

              @Taz742 said in Single Qt Application With multiple windows/Widgets on two screens machine.:

              @IamSumit2 said in Single Qt Application With multiple windows/Widgets on two screens machine.:

              I want to show one screen on my first screen

              Sorry, screen is a monitor? You have two monitor and you want to show first widget in the first monitor and second widget to the second monitor?

              Yes this was my Question.

              Taz742T Offline
              Taz742T Offline
              Taz742
              wrote on last edited by Taz742
              #6

              @IamSumit2
              My answer was a very bad explanation.
              Okay, start again.

              We have 2 monitor, consider the case when an additional (second) monitor is on the right of the main monitor.

              For example:

              First monitor:

              • width: 1920
              • height: 1080

              Second monitor:

              • width: 800
              • height: 600

              The sum of both screens width is the sum 1920 + 800, i.e = 2720.

              QRect desk_rect = m->screenGeometry(1); // it is a second monitor
              int desk_x = desk_rect.width(); // i.e desk_x = 800
              int desk_y = desk_rect.height(); // i.e desk_y = 600
              

              We want to move our second widget to second monitor.

              What does this code mean?

              scndmon->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
              

              scndmon is a widget which we want to show second monitor.
              Just call scndmon->move(); And calculate coordinates.

              desk_x / 2 = 800 / 2 = 400;
              x is a our widget width. Let's assume that its width and height are 400x200. i.e x = 400 / 2 = 200.
              desk_rect.left() is a first monitor width. i.e desk_rect_left() = 1920;

              Now we only have a 'x' coordinate. Wich is 400 + 200 + 1920 = 2520; i.e x = 2520;

              Now calculate 'y' coordinate.
              desk_y / 2 = 600 / 2 = 300;
              y is a our widget height. Wich height is 200. i.e y = 200 / 2 = 100.
              desk_rect.top() = 0;
              y = 300 + 100 = 400;

              It turns out that our coordinates is 2520x400.
              Our form will move(2520, 400), this is the coordinate in the center of the second monitor.
              just call scndmon->showFullScreen();

              Sorry for my bad english! :)

              Do what you want.

              1 Reply Last reply
              1
              • IamSumit2I Offline
                IamSumit2I Offline
                IamSumit2
                wrote on last edited by IamSumit2
                #7

                It didn't work.It is displaying both widgets on same screen. I am getting screen count 2.

                kshegunovK 1 Reply Last reply
                0
                • IamSumit2I IamSumit2

                  It didn't work.It is displaying both widgets on same screen. I am getting screen count 2.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  Get the screens from QGuiApplication and query their (available) geometry with QScreen::geometry.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  2

                  • Login

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