QLabel
을 상속하는 사용자 정의 위젯을 만들고 있는데, 위젯에 사용자에게 표시 할 때 데이터 서식을 지정하는 속성을 갖고 싶습니다.PyQt에서 Q_ENUMS를 사용하는 방법
나는 Q_ENUMS
을 사용하려고하는데,별로 성공하지 못했습니다. Designer에서 속성을 표시 할 수 있지만 저장된 UI 파일은 PyDMLabel::STRING
이라는 열거 형을 나타내지 만 DisplayFormat::STRING
을 기대하지는 않습니다.
class PyDMLabel(QLabel, PyDMWidget):
class DisplayFormat:
DEFAULT = 0
STRING = 1
DECIMAL = 2
EXPONENTIAL = 3
HEX = 4
BINARY = 5
Q_ENUMS(DisplayFormat)
"""
A QLabel with support for Channels and more from PyDM
Parameters
----------
parent : QWidget
The parent widget for the Label
init_channel : str, optional
The channel to be used by the widget.
"""
def __init__(self, parent=None, init_channel=None):
QLabel.__init__(self, parent)
PyDMWidget.__init__(self, init_channel=init_channel)
self.setTextFormat(Qt.PlainText)
self.setTextInteractionFlags(Qt.NoTextInteraction)
self.setText("PyDMLabel")
self._display_format_type = PyDMLabel.DisplayFormat.DEFAULT
@pyqtProperty(DisplayFormat)
def displayFormat(self):
return self._display_format_type
@displayFormat.setter
def displayFormat(self, new_type):
if self._display_format_type != new_type:
self._display_format_type = new_type
Q_ENUMS
와 PyQt는에 대처하는 올바른 방법은 무엇입니까 : 여기
위젯 내 코드?
고맙습니다! 당신의 제안으로 나는 그것을 작동시킬 수있었습니다. 동일한 개념을 사용하여 동적 열거 형을 만들 수 있는지 알고 계십니까? – hhslepicka
@hhslepicka. 나는 정확히 모르겠다. 필자는 PyQt가'Q_ENUMS'을 작동시키기위한 메타 클래스 해킹을한다고 생각합니다. 그래서 클래스 범위에서 정의해야합니다. 그러나 나는 그 주위에 어떤 방법이 있는지 모르겠습니다. – ekhumoro
다시 한번 감사드립니다. 나는 일반적인 열거 형에 대해서도 Qt와 같은 줄에서 무언가를 만드는 법을 또한 조사하려고 노력할 것이고 만약 내가 뭔가를 발견한다면 나는 여기에 다시 올 것이다. – hhslepicka