diff --git a/UI/Main/Main.py b/UI/Main/Main.py index 78addaf..8b22a05 100644 --- a/UI/Main/Main.py +++ b/UI/Main/Main.py @@ -282,6 +282,12 @@ class MainWindow(QMainWindow): x = cursorGlobalPoint.x() y = cursorGlobalPoint.y() + + # 检查是否在标题栏区域,如果不在则不允许调整大小 + if not self._isInTitleBar(cursorGlobalPoint): + self.dir = self.Numbers.NONE + self.setCursor(QCursor(Qt.ArrowCursor)) + return if(tl.x() + self.padding >= x and tl.x() <= x and tl.y() + self.padding >= y and tl.y() <= y): #左上角 @@ -330,11 +336,17 @@ class MainWindow(QMainWindow): def mousePressEvent(self,event): if(event.button()==Qt.LeftButton): - self.isLeftPressDown=True - if(self.dir != self.Numbers.NONE): - self.mouseGrabber() - else: - self.dragPosition = event.globalPos() - self.frameGeometry().topLeft() + # 检查鼠标点击是否在标题栏区域 + if self._isInTitleBar(event.globalPos()): + self.isLeftPressDown=True + if(self.dir != self.Numbers.NONE): + self.mouseGrabber() + else: + self.dragPosition = event.globalPos() - self.frameGeometry().topLeft() + else: + # 不在标题栏区域,不处理拖拽 + self.isLeftPressDown = False + self.dir = self.Numbers.NONE def mouseMoveEvent(self,event): gloPoint = event.globalPos() @@ -383,8 +395,27 @@ class MainWindow(QMainWindow): pass self.setGeometry(rmove) else: - self.move(event.globalPos() - self.dragPosition) - event.accept() + # 只有在标题栏区域才能拖拽移动窗口 + if self._isInTitleBar(event.globalPos()): + self.move(event.globalPos() - self.dragPosition) + event.accept() + + def _isInTitleBar(self, globalPos): + """ + 检查鼠标位置是否在标题栏区域 + :param globalPos: 鼠标全局位置 + :return: 是否在标题栏区域 + """ + # 获取标题栏的全局位置 + titleBarRect = self.topWidget.geometry() + titleBarGlobalTopLeft = self.topWidget.mapToGlobal(titleBarRect.topLeft()) + titleBarGlobalBottomRight = self.topWidget.mapToGlobal(titleBarRect.bottomRight()) + + # 创建全局矩形区域 + titleBarGlobalRect = QRect(titleBarGlobalTopLeft, titleBarGlobalBottomRight) + + # 检查鼠标是否在标题栏区域内 + return titleBarGlobalRect.contains(globalPos) diff --git a/UI/VarManages/VarWidget.py b/UI/VarManages/VarWidget.py index 7537365..ac38ffc 100644 --- a/UI/VarManages/VarWidget.py +++ b/UI/VarManages/VarWidget.py @@ -563,7 +563,8 @@ class TcRtdWidgets(VarWidgets): except Exception: QMessageBox.warning(self, '警告', "量程范围格式错误", QMessageBox.Yes) return - res = Globals.getValue('protocolManage').writeVariableValue(varName, value) + # print(varName, float(value)) + res = Globals.getValue('protocolManage').writeVariableValue(varName, float(value)) if res: forceVars.add(varName) else: