1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-01-17 20:12:54 +08:00

顶层Frameless 窗口 支持圆角

This commit is contained in:
jared 2021-06-28 17:09:28 +08:00
parent 1fc126bbb2
commit 73133b8077
2 changed files with 26 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#pragma once
#include "TaoCommonGlobal.h"
#include <QQuickView>
#include <QRegion>
//无边框窗口,主要用来实现自定义标题栏。
//Windows平台支持拖动和改变大小支持Aero效果
//非Windows平台去掉边框不做其它处理。由Qml模拟resize和拖动。
@ -20,7 +21,30 @@ public:
static QRect calcCenterGeo(const QRect &screenGeo, const QSize &normalSize);
public slots:
void setIsMax(bool isMax);
void setTitleItem(QQuickItem *item);
void setTitleItem(QQuickItem* item);
//设置圆角
void setCornerRadius(int radius)
{
QRect rect(QPoint(), this->geometry().size());
QRect circleRect(0, 0, radius * 2, radius * 2);
QRegion region(circleRect, QRegion::Ellipse);
circleRect.moveRight(rect.right());
region += QRegion(circleRect, QRegion::Ellipse);
circleRect.moveBottom(rect.bottom());
region += QRegion(circleRect, QRegion::Ellipse);
circleRect.moveLeft(rect.left());
region += QRegion(circleRect, QRegion::Ellipse);
region += QRegion(rect.adjusted(radius, 0, -radius, 0), QRegion::Rectangle);
region += QRegion(rect.adjusted(0, radius, 0, -radius), QRegion::Rectangle);
this->setMask(region);
}
signals:
void isMaxChanged(bool isMax);

View File

@ -50,6 +50,7 @@ int main(int argc, char **argv)
view.setMinimumSize({ 800, 600 });
view.resize(1440, 960);
view.moveToScreenCenter();
view.setCornerRadius(5);
trans.beforeUiReady(view.rootContext(), transDir);
appInfo.beforeUiReady(view.rootContext());