所以我有这个带有无框窗口的项目,为了在屏幕上移动它们,为每个窗口制作了这样的功能:
窗口.h
private:
Ui::MainWindow *ui;
void main_mousePressEvent(QMouseEvent *event);
void main_mouseMoveEvent(QMouseEvent *event);
int m_nMouseClick_X_Coordinate;
int m_nMouseClick_Y_Coordinate;
窗口.cpp
void MainWindow::main_mousePressEvent(QMouseEvent *event) {
m_nMouseClick_X_Coordinate = event->position().x();
m_nMouseClick_Y_Coordinate = event->position().y();
//qDebug() << m_nMouseClick_X_Coordinate << " 1 " << m_nMouseClick_Y_Coordinate;
}
void MainWindow::main_mouseMoveEvent(QMouseEvent *event) {
move(event->globalPosition().x()-m_nMouseClick_X_Coordinate,event->globalPosition().y()-m_nMouseClick_Y_Coordinate);
//qDebug() << m_nMouseClick_X_Coordinate << " 2 " << m_nMouseClick_Y_Coordinate;
}
在我重新启动计算机并再次运行程序之前效果很好......由于某种原因,Windows 现在不移动,任何想法发生了什么?
PS Qt 版本。- 6