Increase Checkbox size not its text in QT?

元气小坏坏 提交于 2019-12-19 05:22:06

问题


how to Increase Checkbox size not its text in QT ?

Thanks.


回答1:


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.




回答2:


I would recommend using Qt style sheet.

You can change the size of the indicator :

QCheckBox::indicator {
     width: 40px;
     height: 40px;
}

You'll have to change the image of the indicator, and provide an image with a corresponding size :

QCheckBox::indicator:checked {
     image: url(:/images/checkbox_checked.png);
}



回答3:


I used this:

eyeChk = new QCheckBox("Eyes:");

_eyeChk->setStyleSheet("QCheckBox::indicator { width:150px; height: 150px;} QCheckBox::indicator::checked {image: url(/home/jvdglind/Downloads/280px-PNG_transparency_demonstration_2.png);}");

And just found sound decent default checkbox images.



来源:https://stackoverflow.com/questions/6302428/increase-checkbox-size-not-its-text-in-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!