具有完全透明背景的 qt 小部件 [英] A qt widget with fully transparent background

查看:22
本文介绍了具有完全透明背景的 qt 小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个 qt 小部件,它将充当其他一些小部件的父级,并为它们排序.

I need to create a qt widget, which will act as a parent for some other widgets, and which will order them.

现在的问题是如何让它的背景完全透明?

Now, the question is how do I make it's background fully transparent?

我想这样做:

struct Imp
{
  Imp( QWidget *parent ) : thisWidget( new QWidget( parent ) )
  {
    thisWidget->setAttribute( Qt::WA_TranslucentBackground, true );
  }

  QWidget *thisWidget;
};

你认为我需要设置属性,还是没有它会正常工作?

Do you think that I need to set the attribute, or is it going to work fine without it?

推荐答案

在 Qt4 中默认情况下,QWidget 不会为自己的背景绘制任何内容,只会绘制其子项.如果你想覆盖它,你必须特别告诉小部件通过它的属性之一来绘制它的背景.请注意,从 QWidget 派生的一些小部件会自动绘制背景.

By default in Qt4, a QWidget will draw nothing for its own background, and only its children will be drawn. If you want to override that, you specifically have to tell the widget to draw its background via one of its properties. Note that some widgets derived from QWidget will automatically draw backgrounds.

这篇关于具有完全透明背景的 qt 小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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