Qt designer loads custom components

Purpose: Replace the QLabel component in Qt Designer with your own ROILabel class that can draw the image ROI area.
Solution:

  1. Implement the ROILabel class in your own code, inheriting from QLabel

    # main.py
    class ROILabel(QLabel):
        """
        画的所有roi区域存储在self.rois中
        鼠标左键点击->滑动->释放, 完成一次roi绘制
        鼠标右键取消上一次绘制
        鼠标中键清除历史绘制结果
        """
    
  2. 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.
    Insert image description here
    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.
    Insert image description here
    Insert image description here
    The filled in header file is reflected here, so do not add .pya suffix to the python file

Guess you like

Origin blog.csdn.net/qq_39735236/article/details/127068178