窗口设置无边框
设置无标题栏
setWindowFlags(Qt::FramelessWindowHint | windowFlags());
设置完写缩放函数,发现无法缩放。函数能进去,但无效果。
原因
setWindowFlags(Qt::FramelessWindowHint | windowFlags());
将此代码改为
setWindowFlags(Qt::FramelessWindowHint);
windowFlags是windows默认的一些参数设置,可能有些会影响到缩放的功能,具体参数,可以下去查下。
如果这样也没解决
再加上
代码: setMouseTracking(true)
缩放函数
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
int m_nBorder = 5;
Q_UNUSED(eventType)
MSG *param = static_cast<MSG *>(message);
switch (param->message)
{
case WM_NCHITTEST:
{
int nX = GET_X_LPARAM(param->lParam) - this->geometry().x();
int nY = GET_Y_LPARAM(param->lParam) - this->geometry().y();
if mouse in the child Qwidget of mainfrme, we should not handle it
//if (childAt(nX, nY) != NULL)
// return QWidget::nativeEvent(eventType, message, result);
*result = HTCAPTION;
// if mouse in the border of mainframe,we zoom mainframe
if ((nX > 0) && (nX < m_nBorder))
*result = HTLEFT;
if ((nX > this->width() - m_nBorder) && (nX < this->width()))
*result = HTRIGHT;
if ((nY > 0) && (nY < m_nBorder))
*result = HTTOP;
if ((nY > this->height() - m_nBorder) && (nY < this->height()))
*result = HTBOTTOM;
if ((nX > 0) && (nX < m_nBorder) && (nY > 0)
&& (nY < m_nBorder))
*result = HTTOPLEFT;
if ((nX > this->width() - m_nBorder) && (nX < this->width())
&& (nY > 0) && (nY < m_nBorder))
*result = HTTOPRIGHT;
if ((nX > 0) && (nX < m_nBorder)
&& (nY > this->height() - m_nBorder) && (nY < this->height()))
*result = HTBOTTOMLEFT;
if ((nX > this->width() - m_nBorder) && (nX < this->width())
&& (nY > this->height() - m_nBorder) && (nY < this->height()))
*result = HTBOTTOMRIGHT;
if (*result == HTCAPTION)
{
return false;
}
return true;
}
}
return QMainWindow::nativeEvent(eventType, message, result);
}
自定义带放大缩小标题栏的窗口
自己写的带标题栏,可以设置颜色图标等等,可以拖拽,缩放。
只需要widget继承此类即可。
后续放地址。先Mark一下