PyQt5 QSpinBox - Adding border for anti pressed

PyQt5 QSpinBox - Adding border for anti pressed

To apply a custom border style to a QSpinBox when it's not pressed (i.e., in its normal, non-active state), you can use the QSpinBox::setStyleSheet method with the appropriate CSS-like styling provided by Qt.

Here's a step-by-step example:

  1. Set Up the Environment:

    Install PyQt5 if you haven't already:

    pip install pyqt5 
  2. Implement the QSpinBox Styling:

import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QSpinBox class MyApp(QWidget): def __init__(self): super().__init__() layout = QVBoxLayout(self) spinbox = QSpinBox(self) # Set the style spinbox.setStyleSheet(""" /* This is the normal (non-active) state style */ QSpinBox { border: 2px solid blue; } /* This is the pressed (active) state style */ QSpinBox:pressed { border: 2px solid green; } """) layout.addWidget(spinbox) self.setLayout(layout) self.setWindowTitle('PyQt5 QSpinBox Styling') self.setGeometry(300, 300, 300, 200) app = QApplication(sys.argv) window = MyApp() window.show() sys.exit(app.exec_()) 

In the example:

  • A QSpinBox is styled such that its normal, non-active state has a blue border.
  • When pressed (active), the border color changes to green.

Adjust the styles as needed to meet your design requirements.


More Tags

subscriptions html-agility-pack angular-template-form httpsession debouncing imshow java-10 animated-webp inputbox google-authenticator

More Programming Guides

Other Guides

More Programming Examples