#include "QtWidgetsTest.h"
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtCore/QTime>
#include <QtCore/QTimer>
#include <QtGui/QPainter>
#include <QtGui/QWindow>
#include <QtWidgets/QApplication>
#include <QtWidgets/QStyle>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QActionGroup>
#include <QWKWidgets/widgetwindowagent.h>
#include "widgetframe/windowbar.h"
#include "widgetframe/windowbutton.h"
#pragma execution_character_set("utf-8")
QtWidgetsTest::QtWidgetsTest(QWidget* parent)
: QMainWindow(parent)
{
ui.setupUi(this);
installWindowAgent();
loadFramStyleSheet(Dark);
initialBrowserTree();
setWindowTitle(QString::fromUtf8("三维可视化系统"));
}
QtWidgetsTest::~QtWidgetsTest()
{}
static inline void emulateLeaveEvent(QWidget* widget)
{
Q_ASSERT(widget);
if (!widget)
{
return;
}
QTimer::singleShot(0, widget, [widget]()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
const QScreen* screen = widget->screen();
#else
const QScreen* screen = widget->windowHandle()->screen();
#endif
const QPoint globalPos = QCursor::pos(screen);
if (!QRect(widget->mapToGlobal(QPoint{ 0, 0 }), widget->size()).contains(globalPos))
{
QCoreApplication::postEvent(widget, new QEvent(QEvent::Leave));
if (widget->testAttribute(Qt::WA_Hover))
{
const QPoint localPos = widget->mapFromGlobal(globalPos);
const QPoint scenePos = widget->window()->mapFromGlobal(globalPos);
static constexpr const auto oldPos = QPoint{};
const Qt::KeyboardModifiers modifiers = QGuiApplication::keyboardModifiers();
#if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
const auto event =
new QHoverEvent(QEvent::HoverLeave, scenePos, globalPos, oldPos, modifiers);
Q_UNUSED(localPos);
#elif (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
const auto event = new QHoverEvent(QEvent::HoverLeave, localPos, globalPos, oldPos, modifiers);
Q_UNUSED(scenePos);
#else
const auto event = new QHoverEvent(QEvent::HoverLeave, localPos, oldPos, modifiers);
Q_UNUSED(scenePos);
#endif
QCoreApplication::postEvent(widget, event);
}
}
});
}
bool QtWidgetsTest::event(QEvent* event)
{
switch (event->type())
{
case QEvent::WindowActivate:
{
auto menu = menuWidget();
menu->setProperty("bar-active", true);
style()->polish(menu);
break;
}
case QEvent::WindowDeactivate:
{
auto menu = menuWidget();
menu->setProperty("bar-active", false);
style()->polish(menu);
break;
}
default:
break;
}
return QMainWindow::event(event);
}
void QtWidgetsTest::closeEvent(QCloseEvent* event)
{
event->accept();
}
void QtWidgetsTest::installWindowAgent()
{
windowAgent = new QWK::WidgetWindowAgent(this);
windowAgent->setup(this);
auto windowBar = new QWK::WindowBar();
auto menuBar = [this]()
{
auto menuBar = new QMenuBar();
// Virtual menu
auto file = new QMenu(tr("File(&F)"), menuBar);
file->addAction(new QAction(tr("New(&N)"), menuBar));
file->addAction(new QAction(tr("Open(&O)"), menuBar));
file->addSeparator();
auto edit = new QMenu(tr("Edit(&E)"), menuBar);
edit->addAction(new QAction(tr("Undo(&U)"), menuBar));
edit->addAction(new QAction(tr("Redo(&R)"), menuBar));
// Theme action
auto darkAction = new QAction(tr("Enable dark theme"), menuBar);
darkAction->setCheckable(true);
connect(darkAction, &QAction::triggered, this, [this](bool checked) {
loadFramStyleSheet(checked ? Dark : Light);
});
connect(this, &QtWidgetsTest::themeChanged, darkAction, [this, darkAction]() {
darkAction->setChecked(currentTheme == Dark); //
});
auto dwmBlurAction = new QAction(tr("Enable DWM blur"), menuBar);
dwmBlurAction->setCheckable(true);
connect(dwmBlurAction, &QAction::toggled, this, [this](bool checked) {
if (!windowAgent->setWindowAttribute(QStringLiteral("dwm-blur"), checked)) {
return;
}
setProperty("custom-style", checked);
style()->polish(this);
});
auto acrylicAction = new QAction(tr("Enable acrylic material"), menuBar);
acrylicAction->setCheckable(true);
connect(acrylicAction, &QAction::toggled, this, [this](bool checked) {
if (!windowAgent->setWindowAttribute(QStringLiteral("acrylic-material"), true)) {
return;
}
setProperty("custom-style", checked);
style()->polish(this);
});
auto micaAction = new QAction(tr("Enable mica"), menuBar);
micaAction->setCheckable(true);
connect(micaAction, &QAction::toggled, this, [this](bool checked) {
if (!windowAgent->setWindowAttribute(QStringLiteral("mica"), checked)) {
return;
}
setProperty("custom-style", checked);
style()->polish(this);
});
auto micaAltAction = new QAction(tr("Enable mica alt"), menuBar);
micaAltAction->setCheckable(true);
connect(micaAltAction, &QAction::toggled, this, [this](bool checked) {
if (!windowAgent->setWindowAttribute(QStringLiteral("mica-alt"), checked)) {
return;
}
setProperty("custom-style", checked);
style()->polish(this);
});
// Real menu
auto settings = new QMenu(tr("Settings(&S)"), menuBar);
settings->addAction(darkAction);
settings->addSeparator();
settings->addAction(dwmBlurAction);
settings->addAction(acrylicAction);
settings->addAction(micaAction);
settings->addAction(micaAltAction);
menuBar->addMenu(file);
menuBar->addMenu(edit);
menuBar->addMenu(settings);
return menuBar;
}();
menuBar->setObjectName(QStringLiteral("win-menu-bar"));
auto titleLabel = new QLabel();
titleLabel->setAlignment(Qt::AlignCenter);
titleLabel->setObjectName(QStringLiteral("win-title-label"));
auto iconButton = new QWK::WindowButton();
iconButton->setObjectName(QStringLiteral("icon-button"));
iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto minButton = new QWK::WindowButton();
minButton->setObjectName(QStringLiteral("min-button"));
minButton->setProperty("system-button", true);
minButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto maxButton = new QWK::WindowButton();
maxButton->setCheckable(true);
maxButton->setObjectName(QStringLiteral("max-button"));
maxButton->setProperty("system-button", true);
maxButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
auto closeButton = new QWK::WindowButton();
closeButton->setObjectName(QStringLiteral("close-button"));
closeButton->setProperty("system-button", true);
closeButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
windowBar->setIconButton(iconButton);
windowBar->setMinButton(minButton);
windowBar->setMaxButton(maxButton);
windowBar->setCloseButton(closeButton);
windowAgent->setTitleBar(windowBar);
windowBar->setMenuBar(menuBar);
windowBar->setTitleLabel(titleLabel);
windowBar->setHostWidget(this);
windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton);
windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton);
windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton);
windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton);
windowAgent->setHitTestVisible(menuBar, true);
setMenuWidget(windowBar);
connect(iconButton, &QAbstractButton::clicked, windowAgent, [this, iconButton] {
iconButton->setProperty("double-click-close", false);
// Pick a suitable time threshold
QTimer::singleShot(75, windowAgent, [this, iconButton]() {
if (iconButton->property("double-click-close").toBool())
return;
windowAgent->showSystemMenu(iconButton->mapToGlobal(QPoint{ 0, iconButton->height() }));
});
});
connect(iconButton, &QWK::WindowButton::doubleClicked, this, [iconButton, this]() {
iconButton->setProperty("double-click-close", true);
close();
});
connect(windowBar, &QWK::WindowBar
没有合适的资源?快使用搜索试试~ 我知道了~
Qt完美的无边框解决方案示例源码
共72个文件
h:29个
svg:16个
dll:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 60 浏览量
2024-03-21
15:42:36
上传
评论
收藏 380KB ZIP 举报
温馨提示
1、包含编译好的qwindowkit库; 2、包含可运行exe文件; 3、可编译通过的源码; 4、Windows编译环境: MSVC 2019, 2022 + Qt 5.12 or higher 5、详情参考博客:https://blog.csdn.net/m0_37251750/article/details/136909882
资源推荐
资源详情
资源评论
收起资源包目录
QFramelessWidget.zip (72个子文件)
QFramelessWidget
QtWidgetsTest.ui 2KB
QtWidgetsTest.vcxproj.filters 2KB
QtWidgetsTest.vcxproj.user 168B
res
image
branch-open - 副本.svg 738B
branch-closed2.svg 738B
branch-end.svg 1024B
branch-open.svg 750B
background.png 16KB
branch-end - 副本.svg 1015B
branch-line - 副本.svg 910B
branch-more - 副本.svg 1KB
branch-closed.svg 779B
branch-more.svg 1KB
branch-line.svg 922B
app
example.png 3KB
example.icns 17KB
example.ico 52KB
qss
light-style.qss 3KB
dark-style.qss 3KB
window-bar
minimize.svg 477B
more-line.svg 423B
restore.svg 574B
fullscreen.svg 2KB
close.svg 458B
maximize.svg 339B
main.cpp 316B
widgetframe
windowbar.cpp 9KB
windowbutton.cpp 2KB
windowbar_p.h 1KB
windowbar.h 2KB
windowbutton_p.h 666B
windowbutton.h 1KB
x64
Debug
QWKCored.dll 303KB
QWKWidgetsd.dll 125KB
QtWidgetsTest.exe 234KB
QtWidgetsTest.h 738B
QtWidgetsTest.vcxproj 4KB
QtWidgetsTest.qrc 845B
QtWidgetsTest.sln 901B
QtWidgetsTest.cpp 13KB
QWindowkit
include
QWKWidgets
widgetwindowagent.h 2KB
qwkwidgetsglobal.h 564B
private
widgetwindowagent_p.h 1KB
widgetitemdelegate_p.h 2KB
QWKCore
qwindowkit_windows.h 6KB
qwindowkit_linux.h 267B
qwkglobal.h 1011B
qwkconfig.h 487B
windowagentbase.h 1KB
styleagent.h 1KB
private
windowitemdelegate_p.h 2KB
qtwindowcontext_p.h 1KB
nativeeventfilter_p.h 2KB
sharedeventfilter_p.h 2KB
win32windowcontext_p.h 3KB
windowagentbase_p.h 1KB
qwkglobal_p.h 2KB
styleagent_p.h 1KB
cocoawindowcontext_p.h 1KB
qwkwindowsextra_p.h 18KB
windows10borderhandler_p.h 4KB
systemwindow_p.h 5KB
winidchangeeventfilter_p.h 1KB
abstractwindowcontext_p.h 5KB
lib
QWKCore.lib 42KB
QWKWidgets.lib 21KB
QWKWidgetsd.lib 21KB
QWKCored.lib 42KB
bin
QWKCore.dll 82KB
QWKWidgets.dll 36KB
QWKCored.dll 303KB
QWKWidgetsd.dll 125KB
共 72 条
- 1
资源评论
欧特克_Glodon
- 粉丝: 4w+
- 资源: 64
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功