您的位置:首页 > 编程语言 > Qt开发

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

2014-07-24 11:05 423 查看
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);
记录一下, 免得忘了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: