PyQt5 QSpinBox - Clearing the Mask

PyQt5 QSpinBox - Clearing the Mask

If you have set an input mask on a QSpinBox in PyQt5 and wish to clear it, you can simply call the setInputMask() method with an empty string.

Here's an example to illustrate:

  1. Setup PyQt5:

    If you haven't already installed PyQt5, you can do so with pip:

    pip install PyQt5 
  2. Example with QSpinBox and Input Mask:

import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QSpinBox, QVBoxLayout, QWidget, QPushButton class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.spinbox = QSpinBox() # Set an input mask: This allows input in the form of 99-99 # (where 9 represents any digit) self.spinbox.setInputMask("99-99") button = QPushButton("Clear Mask") button.clicked.connect(self.clear_mask) layout = QVBoxLayout() layout.addWidget(self.spinbox) layout.addWidget(button) central_widget = QWidget() central_widget.setLayout(layout) self.setCentralWidget(central_widget) def clear_mask(self): # Clear the input mask by setting it to an empty string self.spinbox.setInputMask("") app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_()) 

In the above example, the QSpinBox initially has an input mask that allows values in the format "99-99". The "Clear Mask" button removes this input mask when clicked, allowing the spin box to accept any integer value.


More Tags

iformfile cross-join aws-sdk-ruby filepath uitextfield macros bitset color-depth combobox maya

More Programming Guides

Other Guides

More Programming Examples