Purpose: Replace the QLabel component in Qt Designer with your own ROILabel class that can draw the image ROI area.
Solution:
-
Implement the ROILabel class in your own code, inheriting from QLabel
# main.py class ROILabel(QLabel): """ 画的所有roi区域存储在self.rois中 鼠标左键点击->滑动->释放, 完成一次roi绘制 鼠标右键取消上一次绘制 鼠标中键清除历史绘制结果 """
-
Drag the QLabel component in Qt Designer, click on the component, right-click and select "
提升为
"
, fill in the relevant information of the new component in the pop-up "Promoted Widget", and click Add.
After adding, click Promote, and the custom component will be switched successfully.
The header file is a file that implements a custom component class, and python files do not need to be suffixed.py
.
Recompile the ui file, and the custom class will appear in the generated ui.py file.
The filled in header file is reflected here, so do not add.py
a suffix to the python file