窗口设置为Qt::Popup时, 如何去掉窗口阴影?

CFlowerWid::CFlowerWid(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::Popup);
	setAttribute(Qt::WA_TranslucentBackground);
}

窗口设置为Qt::Popup时, window7下会自带一个阴影. 

如何去掉窗口阴影?

代码:

bool CFlowerWid::event(QEvent *event)
{
	// class_ameneded 不能是custommenu的成员, 因为winidchange事件触发时, 类成员尚未初始化
	static bool class_amended = false; 
	if (event->type() == QEvent::WinIdChange)
	{
		HWND hwnd = reinterpret_cast<HWND>(winId());
		if (class_amended == false)
		{
			class_amended = true;
			DWORD class_style = ::GetClassLong(hwnd, GCL_STYLE);
			class_style &= ~CS_DROPSHADOW;
			::SetClassLong(hwnd, GCL_STYLE, class_style); // windows系统函数
		}
	}
	return QWidget::event(event);
}

需要执行Windows函数,
SetClassLong(hwnd, GCL_STYLE, class_style);
记录一下, 免得忘了.

你可能感兴趣的:(windows,阴影)