PyQt5 - Setting skin to view part of combobox when mouse hover

PyQt5 - Setting skin to view part of combobox when mouse hover

To set a "skin" or style to the view part of a QComboBox when the mouse hovers over it, you'll be dealing primarily with the Qt Style Sheets (QSS). QSS provides a way to style Qt widgets, similar to how CSS is used for styling web content.

Here's how you can style the view part (the dropdown list) of a QComboBox when the mouse hovers over it:

import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QComboBox class App(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): layout = QVBoxLayout() combo = QComboBox(self) combo.addItems(['Option 1', 'Option 2', 'Option 3', 'Option 4']) layout.addWidget(combo) # Styling the QComboBox dropdown when mouse hovers over it combo.setStyleSheet(""" QComboBox QAbstractItemView { background-color: white; } QComboBox QAbstractItemView::item:hover { background-color: rgba(0, 100, 200, 100); color: white; } """) self.setLayout(layout) self.setWindowTitle('ComboBox Styling') self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = App() sys.exit(app.exec_()) 

In this example:

  • We set the background color of the dropdown (QAbstractItemView) to white.
  • When an item in the dropdown is hovered over (QAbstractItemView::item:hover), its background color is set to a blue shade, and the text color is set to white.

More Tags

office365api content-security-policy puzzle http-status-code-304 jersey google-signin android-4.2-jelly-bean intellij-plugin android-paging-library setstate

More Programming Guides

Other Guides

More Programming Examples