PySide6 GUI 编程(14):QDial的使用

2024-07-24 19:19:35 浏览数 (3)

示例代码

代码语言:python代码运行次数:0复制
from PySide6.QtWidgets import QApplication, QDial, QMainWindow


def dial_mouse_changed(value: int):
    print('dial text changed:', value)


class MyDial(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('Analogue Dial')
        self.dial = QDial()
        self.dial.setRange(-100, 100)
        self.dial.setSingleStep(1)
        self.dial.sliderMoved.connect(dial_mouse_changed)
        self.dial.sliderReleased.connect(self.dial_released)
        self.dial.sliderPressed.connect(self.dial_pressed)

        self.setCentralWidget(self.dial)

    def dial_pressed(self):
        print('dial pressed:', self.dial.sliderPosition())

    def dial_released(self):
        print('dial released:', self.dial.sliderPosition())


if __name__ == '__main__':
    app = QApplication()
    ins = MyDial()
    ins.show()
    app.exec()

运行效果

运行效果运行效果

0 人点赞