C++ 在虚拟桌面qt中获取特定屏幕的中心
嘿,伙计们,我需要在qt下获得虚拟桌面中特定屏幕的分辨率,并在给定屏幕周围移动窗口。我试过了C++ 在虚拟桌面qt中获取特定屏幕的中心,c++,qt,C++,Qt,嘿,伙计们,我需要在qt下获得虚拟桌面中特定屏幕的分辨率,并在给定屏幕周围移动窗口。我试过了 QRect screenSize = desktopWidget.availableGeometry(desktopWidget.screen(ui.monitorNumberComboBox->currentIndex())); 现在当我执行 void MyWindow::setCoordinates(int x, int y) { this->move((x-(this->
QRect screenSize = desktopWidget.availableGeometry(desktopWidget.screen(ui.monitorNumberComboBox->currentIndex()));
现在当我执行
void MyWindow::setCoordinates(int x, int y)
{
this->move((x-(this->width())/2),(y-(this->height()/2)));
//sets center of window on given coordinates
}
window->setCoordinates(screenSize.width()/2, screenSize.height()/2);
它工作得很好,但只适用于主屏幕。是否可以将其用于不同的屏幕,按索引选择?我想您需要呼叫:
[..]
QPoint center = screenSize.center(); // Get the center of the screen rect.
window->setCoordinates(center.x(), center.y());
我想你需要打电话:
[..]
QPoint center = screenSize.center(); // Get the center of the screen rect.
window->setCoordinates(center.x(), center.y());
不幸的是,这不适用于主屏幕以外的屏幕,无论如何,感谢您的时间不幸的是,这不适用于主屏幕以外的屏幕,无论如何,感谢您的时间