紀錄一下關於 LabelImg 程式在執行過程中的各項問題處理
# float error
跟 pyqt 相關,需要修改程式碼
## 修改1
先找到下面檔案位置,會在 package 的位置,基本會在 ".venv\Lib\site-packages\labelImg"

打開 labelImg.py,在 class MainWindow(QMainWindow, WindowMixin): 之前複製下面程式碼
```
class QPainterx(QPainter):
def drawLine(self, x1: float, y1: float, x2: float, y2: float):
super().drawLine(int(x1), int(y1), int(x2), int(y2))
def drawRect(self, x: float, y: float, w: float, h: float):
super().drawRect(int(x), int(y), int(w), int(h))
def drawText(self, x: float, y: float, s: object):
super().drawText(int(x), int(y), s)
```
結果如下
```
def toolbar(self, title, actions=None):
toolbar = ToolBar(title)
toolbar.setObjectName(u'%sToolBar' % title)
# toolbar.setOrientation(Qt.Vertical)
toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
if actions:
add_actions(toolbar, actions)
self.addToolBar(Qt.LeftToolBarArea, toolbar)
return toolbar
class QPainterx(QPainter):
def drawLine(self, x1: float, y1: float, x2: float, y2: float):
super().drawLine(int(x1), int(y1), int(x2), int(y2))
def drawRect(self, x: float, y: float, w: float, h: float):
super().drawRect(int(x), int(y), int(w), int(h))
def drawText(self, x: float, y: float, s: object):
super().drawText(int(x), int(y), s)
class MainWindow(QMainWindow, WindowMixin):
FIT_WINDOW, FIT_WIDTH, MANUAL_ZOOM = list(range(3))
def __init__(self, default_filename=None, default_prefdef_class_file=None, default_save_dir=None):
super(MainWindow, self).__init__()
self.setWindowTitle(__appname__)
# Load setting in the main thread
```
## 修改2
找到 self.canvas = Canvas(parent=self),在下方新增程式碼,結果如下
```
self.canvas = Canvas(parent=self)
self.canvas._painter = QPainterx()
self.canvas.zoomRequest.connect(self.zoom_request)
self.canvas.set_drawing_shape_to_square(settings.get(SETTING_DRAW_SQUARE, False))
```
# Reference
https://blog.csdn.net/wangpjpj/article/details/142451247