Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在虚拟桌面qt中获取特定屏幕的中心_C++_Qt - Fatal编程技术网

C++ 在虚拟桌面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->

嘿,伙计们,我需要在qt下获得虚拟桌面中特定屏幕的分辨率,并在给定屏幕周围移动窗口。我试过了

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());

不幸的是,这不适用于主屏幕以外的屏幕,无论如何,感谢您的时间不幸的是,这不适用于主屏幕以外的屏幕,无论如何,感谢您的时间