Unsolved Single Qt Application With multiple windows/Widgets on two screens machine.
-
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.
-
Cool. Are you having some trouble with it that you'd like help with, or just kind of making an announcement?
-
@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?
-
@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();
-
@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.
-
@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! :)
-
It didn't work.It is displaying both widgets on same screen. I am getting screen count 2.
-
Get the screens from
QGuiApplication
and query their (available) geometry with QScreen::geometry.