📜  PyQt5 QDial - 范围改变信号

📅  最后修改于: 2022-05-13 01:54:41.171000             🧑  作者: Mango

PyQt5 QDial - 范围改变信号

在本文中,我们将了解如何获得 QDial 的量程变化信号。当滑块范围发生变化时会发出此信号,默认情况下 QDial 的范围是 0 到 99,尽管我们可以随时借助setRange方法进行更改。

为了做到这一点,我们使用带有 QDial 对象的rangeChanged方法

下面是实现

# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
  
  
class Window(QMainWindow):
  
    def __init__(self):
        super().__init__()
  
        # setting title
        self.setWindowTitle("Python ")
  
        # setting geometry
        self.setGeometry(100, 100, 500, 400)
  
        # calling method
        self.UiComponents()
  
        # showing all the widgets
        self.show()
  
    # method for components
    def UiComponents(self):
  
        # creating QDial object
        dial = QDial(self)
  
        # setting geometry to the dial
        dial.setGeometry(100, 100, 100, 100)
  
        # creating a label
        label = QLabel("GeeksforGeeks", self)
  
        # setting geometry to the label
        label.setGeometry(220, 125, 200, 60)
  
        # making label multiline
        label.setWordWrap(True)
  
        # range changed signal
        dial.rangeChanged.connect(lambda: label.setText("Range Change Signal Emitted"))
  
        # setting range of dial
        dial.setRange(0, 1000)
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

输出 :