0
0 комментариев

Как в Qt Designer заменить класс QLabel на ExtendedQLabel для PyQt5?

ExtendedQLabel.py:

from PyQt5.QtWidgets import QLabel
from PyQt5.QtCore import pyqtSignal
 
 
class ExtendedQLabel(QLabel):
 
    clicked = pyqtSignal()
 
    def __init(self, parent):
        QLabel.__init__(self, parent)
 
    def mouseReleaseEvent(self, e):
        QLabel.mouseReleaseEvent(self, e)
        self.clicked.emit()

В Qt Designer делаю так:
Qt Designer

Вот XML:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Widget</class>
 <widget class="QWidget" name="Widget">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>570</width>
    <height>462</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Widget</string>
  </property>
  <widget class="QListWidget" name="listWidget">
   <property name="geometry">
    <rect>
     <x>335</x>
     <y>20</y>
     <width>221</width>
     <height>371</height>
    </rect>
   </property>
  </widget>
  <widget class="QPushButton" name="pushButton">
   <property name="geometry">
    <rect>
     <x>350</x>
     <y>410</y>
     <width>81</width>
     <height>31</height>
    </rect>
   </property>
   <property name="text">
    <string>PushButton</string>
   </property>
  </widget>
  <widget class="QPushButton" name="pushButton_2">
   <property name="geometry">
    <rect>
     <x>460</x>
     <y>410</y>
     <width>81</width>
     <height>31</height>
    </rect>
   </property>
   <property name="text">
    <string>PushButton</string>
   </property>
  </widget>
  <widget class="ExtendedQLabel" name="label">
   <property name="geometry">
    <rect>
     <x>10</x>
     <y>10</y>
     <width>311</width>
     <height>301</height>
    </rect>
   </property>
   <property name="text">
    <string>TextLabel</string>
   </property>
  </widget>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <customwidgets>
  <customwidget>
   <class>ExtendedQLabel</class>
   <extends>QLabel</extends>
   <header location="global">extendedqlabel</header>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>


Добавить комментарий