Open In App

PyQt5 – Background color to editable ComboBox when mouse hover

Last Updated : 22 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will see how we can set background color to the editable combo box when mouse hover over it. This background color will be shown only when combo box will be in editable state and mouse hover over it. In order to make editable combo box we use setEditable method

In order to do this we have to change the style sheet code of the combo box, below is the style sheet code

QComboBox::editable:hover
{
background-color : lightgreen;
}

Below is the implementation




# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
  
  
class Window(QMainWindow):
  
    def __init__(self):
        super().__init__()
  
        # setting title
        self.setWindowTitle("Python ")
  
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
  
        # calling method
        self.UiComponents()
  
        # showing all the widgets
        self.show()
  
    # method for widgets
    def UiComponents(self):
  
        # creating a combo box widget
        self.combo_box = QComboBox(self)
  
        # setting geometry of combo box
        self.combo_box.setGeometry(200, 150, 150, 30)
  
        # geek list
        geek_list = ["Sayian", "Super Sayian", "Super Sayian 2", "Super Sayian B"]
  
        # making combo box editable
        self.combo_box.setEditable(True)
  
        # adding list of items to combo box
        self.combo_box.addItems(geek_list)
  
        # adding background color to the combo box when it is editable
        # and mouse hover over it
        self.combo_box.setStyleSheet("QComboBox::editable:hover"
                                     "{"
                                     "background-color: lightgreen;"
                                     "}")
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())


Output :



Similar Reads

PyQt5 - Background color to non editable ComboBox when mouse hover
In this article we will see how we can set background color to the non editable combo box when mouse hover over it. This background color will be shown only when combo box will be in non editable state and mouse hover over it. In order to do this we have to change the style sheet code of the combo box, below is the style sheet code QComboBox::!edit
2 min read
PyQt5 – Set background color to non editable OFF state ComboBox when mouse hover
In this article we will see how to set the background color to the non editable combo box which is currently in the OFF state and when mouse hover over it. OFF state of the combo box is when the list menu is not opened. This background color will only appear if the combo box is non editable and in OFF state and mouse hover over combo box. In order
2 min read
PyQt5 – Background color to editable OFF state ComboBox on mouse hover
In this article we will see how to set the background color to the editable combo box which is currently in the OFF state and when hover over it. OFF state of the combo box is when the list menu is not opened. This background color will only appear if the combo box is editable and in OFF state and when cursor hover over combo box. Combo box is made
2 min read
PyQt5 - Set background color to lineedit of non editable ComboBox on mouse hover
In this article we will see how we can set the background color to the line edit part of the non editable combo box when mouse hover over it, line edit part of the combo box is in which text is shown and edit. Note : When we add line edit object to the combo box it make the combo box editable therefore there is need to make the line edit non editab
2 min read
PyQt5 - Background image to lineedit part of non-editable ComboBox when mouse hover
In this article we will see how we can set background image to the line edit part of the non-editable combo box when mouse hover over it. Line edit is the part of combo box which is used to see the selected text and edit the text. In order to set and get the line edit object of the combo box we use setLineEdit and lineEdit method.Note : When we add
2 min read
PyQt5 – Background image to editable ComboBox when mouse hover
In this article we will see how we can set background image to the combo box when it is editable and mouse hover over it. By default combo box has no image although we can set image to it. Background image will appear only when combo box is in editable state and mouse hover over it. Editable state of combo box is when user and set text to the combo
2 min read
PyQt5 – Background image to non-editable ComboBox when mouse hover
In this article we will see how we can set background image to the combo box when it is non-editable and mouse hover over it. By default combo box has no image although we can set image to it. Background image will appear only when combo box is in non-editable state and cursor is over the combo box. Normal combo box can be made editable with the he
2 min read
PyQt5 – Background image to non-editable OFF state ComboBox when mouse hover
In this article we will see how we can set background image to the combo box when it is non-editable off state and mouse hover over it. By default combo box has no image although we can set image to it. Background image will appear only when combo box is in non-editable state, in off state and mouse hover over it. OFF state is when list view is not
2 min read
PyQt5 – Background image to editable OFF state ComboBox when mouse hover
In this article we will see how we can set background image to the combo box when it is editable off state and mouse hover over it. By default combo box has no image although we can set image to it. Background image will appear only when combo box is in editable state, in off state and mouse hover over it. OFF state is when list view is not open. I
2 min read
PyQt5 ComboBox - Different border color when non-editable and mouse hover
In this article we will see how we can set different border color to the combo box when it is non-editable and mouse hover over it, when we set border to the combo box it is of same color for all the sides although we can change color of each sides respectively. Colorful border will only appear combo box is non-editable and cursor is on the widget.
2 min read