赞
踩
//头文件
public:
void setResizable(bool);//设置鼠标是否可以拖动改变大小
protected:
void mouseMoveEvent(QMouseEvent *event) override;//拖动鼠标
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
private:
bool m_bCanResize;//鼠标移动标志
QPoint m_mousePoint;
bool m_iFlag;
void MainWindow::setResizable(bool bCanResize)
{
m_bCanResize = bCanResize;
}
//鼠标移动位置
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
if (m_iFlag && (event->buttons() == Qt::LeftButton)) {
bool flag=this->isMaximized();
if(flag)
{
this->showNormal();
resize(1536,864);
this->setResizable(true);
}
move(event->globalPos() - m_mousePoint);
event->accept();
}
}
void MainWindow::mousePressEvent(QMouseEvent *event)
{
int y = event->pos().y();
if ((event->buttons() == Qt::LeftButton) && (y <= 58)) {
m_iFlag = true;
m_mousePoint = event->globalPos() - this->pos();
event->accept();
}
}
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
{
m_iFlag = false;
QWidget::mouseReleaseEvent(event);
}
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
this->setWindowTitle(QStringLiteral("时间分析"));//下面菜单栏文本
this->setWindowIcon(QIcon(":/res/logo.png"));//修改菜单栏图标
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。