增加无边框以及退出、最大化支持
This commit is contained in:
parent
42bfcf1957
commit
0db572fa71
Binary file not shown.
57
xyylMCWEACSystem/framelesswindow.cpp
Normal file
57
xyylMCWEACSystem/framelesswindow.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "FramelessWindow.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QGridLayout>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
|
||||
struct FramelessWindowPrivate {
|
||||
FramelessWindowPrivate(QWidget *contentWidget) : contentWidget(contentWidget) {}
|
||||
|
||||
QWidget *contentWidget;
|
||||
QPoint mousePressedPosition; // 鼠标按下时的坐标
|
||||
QPoint windowPositionAsDrag; // 鼠标按小时窗口左上角的坐标
|
||||
};
|
||||
|
||||
FramelessWindow::FramelessWindow(QWidget *contentWidget, QWidget *parent) : QWidget(parent) {
|
||||
setWindowFlags(Qt::FramelessWindowHint); // 去掉边框
|
||||
setAttribute(Qt::WA_TranslucentBackground); // 背景透明
|
||||
|
||||
d = new FramelessWindowPrivate(contentWidget);
|
||||
|
||||
// 添加阴影
|
||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(contentWidget);
|
||||
shadowEffect->setColor(Qt::lightGray);
|
||||
shadowEffect->setBlurRadius(4); // 阴影的大小
|
||||
shadowEffect->setOffset(0, 0);
|
||||
contentWidget->setGraphicsEffect(shadowEffect);
|
||||
|
||||
// 添加到窗口中
|
||||
QGridLayout *lo = new QGridLayout();
|
||||
lo->addWidget(contentWidget, 0, 0);
|
||||
lo->setContentsMargins(4, 4, 4, 4); // 注意和阴影大小的协调
|
||||
setLayout(lo);
|
||||
}
|
||||
|
||||
FramelessWindow::~FramelessWindow() {
|
||||
delete d;
|
||||
}
|
||||
|
||||
void FramelessWindow::mousePressEvent(QMouseEvent *e) {
|
||||
// 记录鼠标按下时全局的位置和窗口左上角的位置
|
||||
d->mousePressedPosition = e->globalPos();
|
||||
d->windowPositionAsDrag = pos();
|
||||
}
|
||||
|
||||
void FramelessWindow::mouseReleaseEvent(QMouseEvent *e) {
|
||||
Q_UNUSED(e)
|
||||
// 鼠标放开始设置鼠标按下的位置为 null,表示鼠标没有被按下
|
||||
d->mousePressedPosition = QPoint();
|
||||
}
|
||||
|
||||
void FramelessWindow::mouseMoveEvent(QMouseEvent *e) {
|
||||
if (!d->mousePressedPosition.isNull()) {
|
||||
// 鼠标按下并且移动时,移动窗口, 相对于鼠标按下时的位置计算,是为了防止误差累积
|
||||
QPoint delta = e->globalPos() - d->mousePressedPosition;
|
||||
move(d->windowPositionAsDrag + delta);
|
||||
}
|
||||
}
|
23
xyylMCWEACSystem/framelesswindow.h
Normal file
23
xyylMCWEACSystem/framelesswindow.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef FRAMELESSWINDOW_H
|
||||
#define FRAMELESSWINDOW_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
struct FramelessWindowPrivate;
|
||||
|
||||
class FramelessWindow : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FramelessWindow(QWidget *contentWidget, QWidget *parent = 0);
|
||||
~FramelessWindow();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
||||
void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
FramelessWindowPrivate *d;
|
||||
};
|
||||
|
||||
#endif // FRAMELESSWINDOW_H
|
@ -34,13 +34,16 @@
|
||||
#include <QStackedWidget>
|
||||
|
||||
#include "navlistwidget.h"
|
||||
#include "framelesswindow.h"
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
FrameWindow mainw;
|
||||
mainw.resize(1000,800);
|
||||
mainw.show();
|
||||
FrameWindow *mainw = new FrameWindow;
|
||||
FramelessWindow *window = new FramelessWindow(mainw);
|
||||
window->resize(300, 400);
|
||||
window->showMaximized();
|
||||
|
||||
//a.setStyleSheet("QWidget{background-color:#ffffff;}");
|
||||
// a.setStyleSheet("QWidget{background: rgb(47, 61, 82);}");
|
||||
QFont globalFont;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QDebug>
|
||||
#include <QApplication>
|
||||
TitleWidget::TitleWidget(QWidget * parent ):QFrame(parent)
|
||||
{
|
||||
init();
|
||||
@ -60,9 +61,17 @@ void TitleWidget::initLay()
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
bool TitleWidget::initConnect()
|
||||
{
|
||||
bool bCon = true;
|
||||
bCon = connect(&m_btnRet,SIGNAL(clicked(bool)),qApp,SLOT(quit()));
|
||||
if(!bCon)
|
||||
{
|
||||
qDebug()<<"connect failed"<<endl;
|
||||
|
||||
|
||||
}
|
||||
return bCon;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ SOURCES += \
|
||||
dataprocesswidget.cpp \
|
||||
devconwidget.cpp \
|
||||
eggwidget.cpp \
|
||||
framelesswindow.cpp \
|
||||
framewindow.cpp \
|
||||
hospitalinfo.cpp \
|
||||
loginwidget.cpp \
|
||||
@ -49,6 +50,7 @@ HEADERS += \
|
||||
dataprocesswidget.h \
|
||||
devconwidget.h \
|
||||
eggwidget.h \
|
||||
framelesswindow.h \
|
||||
framewindow.h \
|
||||
hospitalinfo.h \
|
||||
loginwidget.h \
|
||||
|
Loading…
x
Reference in New Issue
Block a user