当前位置: 代码迷 >> QT开发 >> Qt设置背景有关问题
  详细解决方案

Qt设置背景有关问题

热度:88   发布时间:2016-04-25 03:20:25.0
Qt设置背景问题
   练习了一下关于wegdit里面设置背景功能。有如下代码:
  

  问题就是图中每句语句后的备注。请各位帮忙解答下呗。
------解决方案--------------------
关于autoFillBackground这个属性:

autoFillBackground : bool

This property holds whether the widget background is filled automatically.

If enabled, this property will cause Qt to fill the background of the widget before invoking the paint event. The color used is defined by the QPalette::Window color role from the widget's palette.

In addition, Windows are always filled with QPalette::Window, unless the WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set.

This property cannot be turned off (i.e., set to false) if a widget's parent has a static gradient for its background.

Warning: Use this property with caution in conjunction with Qt Style Sheets. When a widget has a style sheet with a valid background or a border-image, this property is automatically disabled.

By default, this property is false.

QWidget打开这个属性才会有背景,大概是这个意思~
然后QPalette是Qt里面设置颜色的工具,其实这个类很多功能都可以被QSS取代,关于QPalette结合着Qt Designer看或许不错
上面的代码就是设置用图片作为画刷画背景,如果以QPixmap(":/image/back.png")的方式加载图片首先要确保这张图片已经加入了资源文件qrc
  相关解决方案