Labelme(5.10.1)标签选择框跑出屏幕的修复

张开发
2026/4/10 2:58:26 15 分钟阅读

分享文章

Labelme(5.10.1)标签选择框跑出屏幕的修复
遇到的问题在屏幕边缘标注时Labelme的标签选择对话框会一半显示在屏幕外需要手动拖回来影响效率如下图所示解决方法修改Python环境下的Lib\site-packages\labelme\widgets\label_dialog.py文件路径示例如下在popUp方法中将if move: self.move(QtGui.QCursor.pos())替换为if move: # 获取鼠标位置 cursor_pos QtGui.QCursor.pos() # 获取屏幕大小 screen QtWidgets.QApplication.primaryScreen().availableGeometry() # 获取对话框的预期大小 self.adjustSize() dialog_size self.size() # 计算初始位置 x cursor_pos.x() 10 y cursor_pos.y() 10 # 边界检查 - 防止超出屏幕 if x dialog_size.width() screen.right(): x cursor_pos.x() - dialog_size.width() - 10 if x screen.left(): x screen.left() 10 if y dialog_size.height() screen.bottom(): y cursor_pos.y() - dialog_size.height() - 10 if y screen.top(): y screen.top() 10 self.move(x, y)如下图所示修改之后效果如下Labelme原本只是简单地将对话框定位在鼠标位置没有做屏幕边界检查。修改后增加了四个方向的边界判断如果对话框会超出屏幕就自动调整到屏幕内超出右边就移到左边超出下边就移到上边以此类推。

更多文章