PyQt5 QComboBox - Change border style when it is editable

PyQt5 QComboBox - Change border style when it is editable

To change the border style of a QComboBox when it is editable, you can utilize the Qt Stylesheet (QSS) capability. Specifically, you can target the QComboBox[editable="true"] selector to apply styles only when the combo box is editable.

Here's an example to demonstrate how you can change the border style of an editable QComboBox:

import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QComboBox class App(QWidget): def __init__(self): super().__init__() self.layout = QVBoxLayout(self) self.comboBox = QComboBox(self) self.comboBox.addItems(['Option 1', 'Option 2', 'Option 3']) # Make the QComboBox editable self.comboBox.setEditable(True) self.layout.addWidget(self.comboBox) # Style the QComboBox self.setStyleSheet(""" QComboBox[editable="true"] { border: 2px solid red; padding: 5px; } """) if __name__ == '__main__': app = QApplication(sys.argv) ex = App() ex.show() sys.exit(app.exec_()) 

In this example, when the QComboBox is editable, it will have a red border with a width of 2 pixels. You can adjust the stylesheet properties as needed to achieve the desired appearance.


More Tags

rotational-matrices dismiss blue-screen-of-death appbar multiline gantt-chart nginx-config file-transfer webhooks device-policy-manager

More Programming Guides

Other Guides

More Programming Examples