- 遇到的问题: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);
}