Increase check box size not its text using QCheckbox?

前端 未结 3 1956
自闭症患者
自闭症患者 2021-01-07 21:08

How do I increase the size of the check box for the QCheckBox control and not the text size?

Thanks.

3条回答
  •  庸人自扰
    2021-01-07 21:28

    Jérôme has given you good advice. I will just give further examples.

    QCheckBox::indicator {
         width: 40px;
         height: 40px;
     }
    
      QCheckBox::indicator:checked
      {
        image: url(../Checkbox_checked_normal.png);
      }
      QCheckBox::indicator:unchecked
      {
        image: url(../Checkbox_unchecked_normal.png);
      }
    
      QCheckBox::indicator:checked:hover
      {
        image: url(../Checkbox_checked_hovered.png);
      }
      QCheckBox::indicator:unchecked:hover
      {
        image: url(../Checkbox_unchecked_hovered.png);
      }
      QCheckBox::indicator:checked:pressed
      {
        image: url(../Checkbox_checked_pressed.png);
      }
      QCheckBox::indicator:unchecked:pressed
      {
        image: url(../Checkbox_unchecked_pressed.png);
      }
      QCheckBox::indicator:checked:disabled
      {
        image: url(../Checkbox_checked_disabled.png);
      }
    

    Pay attention to difference between url() usages. In my example I am loading images from disk rather than embedded resource system which I find more appropriate. If you start url with (:/...) it loads from embedded resource system.

    Then load your style sheet as below

    QFile file("your path");
    bool bOpened = file.open(QFile::ReadOnly);
    assert (bOpened == true);
    
    QString styleSheet = QLatin1String(file.readAll());
    
    qApp->setStyleSheet (styleSheet);
    

    I hope this helps.

提交回复
热议问题