Qt自定义主窗口的放大,缩小,关闭功能
Qt标题栏无法添加自定义按钮,修改样式也改不了;所以需要自定义标题栏;同时支持拖动,双击放大的功能;
按钮设置
//设置为无边框,自定义关闭,放大,缩小按钮 this->setWindowFlags(Qt::FramelessWindowHint); //顶部按钮响应 connect(ui.pBClose, &QPushButton::clicked, [=]() {close(); }); connect(ui.pBMaxWindow, &QPushButton::clicked, [=]() { if (this->isMaximized()) { this->showNormal(); } else { this->showMaximized(); } }); connect(ui.pBMinWindow, &QPushButton::clicked, [=]() {this->showMinimized(); });
void AlgorithmConfig::mousePressEvent(QMouseEvent * event) { //只能是鼠标左键移动和改变大小 if (event->button() == Qt::LeftButton) { if (ui.widgetToolBar->underMouse()) { m_leftMousePressed = true; //按下时鼠标左键时,窗口在屏幕中的坐标 m_StartPoint = event->globalPos(); } } } void AlgorithmConfig::mouseReleaseEvent(QMouseEvent * event) { m_leftMousePressed = false; } void AlgorithmConfig::mouseDoubleClickEvent(QMouseEvent * event) { if (ui.widgetToolBar->underMouse()) { if (isMaximized()) { showNormal(); } else { showMaximized(); } } }
自己开发了一个股票智能分析软件,功能很强大,需要的关注微信公众号:QStockView