In this article we will see how to set background image to check box. When we create a check box there is no image associated to it although we can set background color to it. Below is the representation of normal check box vs the check box which has image.

In order to do this we have to set background image in style sheet, below is the style sheet code which can be used with the check box object.
QCheckBox
{
background-image : url(image.png);
}
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 ):
checkbox = QCheckBox( 'Geek ?' , self )
checkbox.setGeometry( 200 , 150 , 100 , 30 )
checkbox.setStyleSheet( "QCheckBox"
"{"
"background-image : url(image.png)"
"}" )
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
