PyQt5 Combo Box - Different border size when in OFF state when get pressed

PyQt5 Combo Box - Different border size when in OFF state when get pressed

To set a different border size for a QComboBox in the OFF state when it gets pressed using PyQt5, you'll make use of Qt Style Sheets (QSS) again.

Below is a demonstration of how to achieve this:

import sys from PyQt5.QtWidgets import QApplication, QComboBox, QVBoxLayout, QWidget app = QApplication(sys.argv) # Create a sample widget and layout for demonstration window = QWidget() layout = QVBoxLayout(window) # Create a combo box and add items combo = QComboBox(window) combo.addItems(["Choice 1", "Choice 2", "Choice 3"]) layout.addWidget(combo) # Set style for combo box combo.setStyleSheet(""" QComboBox:off:pressed { border: 5px solid green; } """) window.show() sys.exit(app.exec_()) 

In the above code, the QComboBox:off:pressed selector targets the QComboBox that is:

  • in the off state,
  • and currently being pressed.

We set its border to be 5 pixels wide and green in color. You can adjust this and other properties to further customize the appearance as per your needs.


More Tags

backcolor mod-wsgi react-router-redux visual-studio proxy led drupal verification android-toast firebase-storage

More Programming Guides

Other Guides

More Programming Examples