QT界面拉伸距离自定义

  • 遇到的问题:QDockWidget在浮动状态,边框不好选中
  • 出现原因: Qt 源码中的默认大小为4,当QDockWidget存在子界面的时候,子界面的mousemove没触发 选中
  • 解决方案: 通过windos信号判断鼠标的位置,在确定击中边框
#define SPACE_LENTH 10
bool DockWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
	MSG* winMsg = static_cast<MSG *>(message);
	HWND hWnd = winMsg->hwnd;
	switch (winMsg->message)
	{
	case WM_NCHITTEST:
	{
		if (this->isFloating())
		{
			int xPos = GET_X_LPARAM(winMsg->lParam) - this->frameGeometry().x();
			int yPos = GET_Y_LPARAM(winMsg->lParam) - this->frameGeometry().y();

			if (xPos >= 0 && xPos < SPACE_LENTH)//左边界
			{
				*result = HTLEFT;
				return true;
			}
			else if (xPos > (this->width() - SPACE_LENTH)) //右边界
			{
				*result = HTRIGHT;
				return true;
			}
			else if (yPos >= 0 && yPos < SPACE_LENTH)// 上
			{
				*result = HTTOP;
				return true;
			}
			else if (yPos > (this->height() - SPACE_LENTH))// 下
			{
				*result = HTBOTTOM;
				return true;
			}
			break;
		}
	}
	}

	return QDockWidget::nativeEvent(eventType, message, result);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值