📜  PyQt5 QSpinBox – 检查是否允许包装

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

PyQt5 QSpinBox – 检查是否允许包装

在本文中,我们将了解如何检查旋转框中是否允许换行。 Wrapping 会使从最大值变化值逐步上升到最小值,类似循环一样从最小值变化值下降到最大值。我们可以在setWrapping方法的帮助下使旋转框中的包装允许。

注意:仅当您设置了最小值和最大值时,包装才有意义。

为了做到这一点,我们使用带有旋转框对象的wrapping方法。

下面是实现

# 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, 600, 400)
  
        # calling method
        self.UiComponents()
  
        # showing all the widgets
        self.show()
  
        # method for widgets
    def UiComponents(self):
        # creating spin box
        self.spin = QSpinBox(self)
  
        # setting geometry to spin box
        self.spin.setGeometry(100, 100, 250, 40)
  
        # setting range to the spin box
        self.spin.setRange(0, 9)
  
        # setting prefix to spin
        self.spin.setPrefix("PREFIX ")
  
        # setting suffix to spin
        self.spin.setSuffix(" SUFFIX")
  
        # making spin box wrapping the value
        self.spin.setWrapping(True)
  
        # setting status tip to the spin box
        self.spin.setStatusTip("Small Value")
  
        # creating a label
        self.label = QLabel(self)
  
        # making label multi line
        self.label.setWordWrap(True)
  
        # setting label geometry
        self.label.setGeometry(100, 200, 250, 60)
  
        # checking the wrapping is allowed
        value = self.spin.wrapping()
  
        # setting text to the label
        self.label.setText("Wrapping Allowed ? : " + str(value))
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

输出 :