4

The code below creates a single Dialog window with two checkboxes. Second checkbox was constrained to a 8x8px size with setMaximumSize(8, 8) function. But it appears that the smaller size of the checkbox widget was not applied to the cross icon. So the icon is clipped by the boundaries of the checkbox widget. How to make sure the cross icon is scaled proportionally with the checkbox widget?

enter image description here

from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])

panel=QtGui.QDialog()
panel.setLayout(QtGui.QVBoxLayout())

checkbox1 = QtGui.QCheckBox()
panel.layout().addWidget(checkbox1)

checkbox2 = QtGui.QCheckBox()
checkbox2.setMaximumSize(8, 8)
panel.layout().addWidget(checkbox2)

panel.show()
app.exec_()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
alphanumeric
  • 17,967
  • 64
  • 244
  • 392

1 Answers1

2

In this case it is best to resize using the stylesheet:

{your QCheckbox}.setStyleSheet("QCheckBox::indicator { width: npx; height: mpx;}")

Complete code:

import sys

from PyQt4 import QtGui

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)

    panel = QtGui.QDialog()
    panel.setLayout(QtGui.QVBoxLayout())

    checkbox1 = QtGui.QCheckBox("normal1")
    panel.layout().addWidget(checkbox1)

    checkbox2 = QtGui.QCheckBox("small")
    checkbox2.setStyleSheet("QCheckBox::indicator { width: 10px; height: 10px;}")
    panel.layout().addWidget(checkbox2)

    checkbox1 = QtGui.QCheckBox("normal2")
    panel.layout().addWidget(checkbox1)

    panel.show()
    sys.exit(app.exec_())

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241