如何增加复选框大小而不是QT中的文本?

谢谢。

enter image description here

有帮助吗?

解决方案

Jérôme为您提供了很好的建议。我将举一个进一步的例子。

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);
  }

注意差异 url() 用法。在我的示例中,我正在从磁盘而不是嵌入式资源系统中加载图像,我发现这些系统更合适。如果您使用(:/...)启动URL,则它将从嵌入式资源系统加载。

然后加载您的样式表如下

QFile file("your path");
bool bOpened = file.open(QFile::ReadOnly);
assert (bOpened == true);

QString styleSheet = QLatin1String(file.readAll());

qApp->setStyleSheet (styleSheet);

我希望这有帮助。

其他提示

我建议使用 QT样式表.

您可以更改指示器的大小:

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

您必须更改指示器的图像,并提供具有相应大小的图像:

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

我用了:

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);}");

刚刚找到声音不错的默认复选框图像。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top