PyQt5 QSpinBox - Unset locale

PyQt5 QSpinBox - Unset locale

If you've set a locale to a QSpinBox and want to revert back to the default system locale, you can use the QLocale class from the PyQt5.QtCore module. Specifically, you can set the locale of the QSpinBox to the system locale using QLocale.system().

Here's how you can unset (or revert to system locale) for a QSpinBox:

import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QSpinBox from PyQt5.QtCore import QLocale class AppDemo(QWidget): def __init__(self): super().__init__() layout = QVBoxLayout(self) spin_box = QSpinBox(self) # For demonstration purposes, set a custom locale first custom_locale = QLocale(QLocale.French, QLocale.France) spin_box.setLocale(custom_locale) # Unset the locale (revert back to system locale) system_locale = QLocale.system() spin_box.setLocale(system_locale) layout.addWidget(spin_box) app = QApplication(sys.argv) demo = AppDemo() demo.show() sys.exit(app.exec_()) 

In the above code, we initially set a custom locale (French for this demonstration) to the QSpinBox. Later in the code, we revert the QSpinBox to use the system locale using QLocale.system().


More Tags

runtime.exec django-views android-jetpack-navigation okhttp google-play fileoutputstream point-clouds mat-autocomplete google-cloud-storage alignment

More Programming Guides

Other Guides

More Programming Examples