PyQt5 – Setting border to view part of ComboBox on mouse hover
Last Updated :
04 May, 2020
In this article we will see how we can set border to the view part of the combo box when mouse hover over the view part. View part is basically drop down item list, which shows all the available items, we have to get the view object with the help of view
method, by default combo box uses QListView object.
In order to do this we have to change the style sheet associated with the combo box, below is the style sheet code to do this
QListView::hover
{
border : 3px solid red;
background : white;
}
Below is the implementation
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__()
self .setWindowTitle( "Python " )
self .setGeometry( 100 , 100 , 600 , 400 )
self .UiComponents()
self .show()
def UiComponents( self ):
self .combo_box = QComboBox( self )
self .combo_box.setGeometry( 200 , 150 , 150 , 30 )
geek_list = [ "Sayian" , "Super Sayian" , "Super Sayian 2" , "Super Sayian B" ]
self .combo_box.addItems(geek_list)
self .combo_box.setStyleSheet( "QListView:hover"
"{"
"border : 3px solid red;"
"background : white;"
"}" )
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
When mouse will hover over the view part it will look like this
Share your thoughts in the comments
Please Login to comment...