Qt复选框/工具按钮与自定义/不同的检查/取消选中的图标 [英] Qt checkbox/toolbutton with custom/distinct check/unchecked icons

查看:137
本文介绍了Qt复选框/工具按钮与自定义/不同的检查/取消选中的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个复选框,如控件,其中选中和未选中状态使用自定义图形。我看过所有的文档的QToolButton和QCheckBox,连同QIcon,但找不到任何组合,做我想要的。

I need to have a checkbox like control where the checked and unchecked states use a custom graphic. I've looked at all the docs for QToolButton and QCheckBox, along with QIcon but couldn't find any combination that does what I want.

我只想使用一个图标(实际上是pixmap)处于未选中状态,而处于检查状态的图片则不同。

I just want to use one icon (pixmap actually) in the unchecked state, and a different one in the checked state.

这个感觉很容易,

我也尝试过使用样式表, QToolButton:检查 background-image 种作品,但我不能得到布局正确 - 它的位置/图标。

I've tried using a style sheet as well, and QToolButton:checked with a background-image kind of works but I can't get the layout correct -- it's not positioned/sized as with an icon.

推荐答案

Use :: indicator子项。下面的代码适用于我...

Use ::indicator sub-item. the code below works excellent for me...

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

  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);
  }
  QCheckBox::indicator:unchecked:disabled
  {
    image: url(.../Checkbox_unchecked_disabled.png);
  }

这篇关于Qt复选框/工具按钮与自定义/不同的检查/取消选中的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆