1、Qt边框问题
在使用QWidget或QMainWindow时,关于标题栏无法设定背景以及拖动的问题,与windows系统显得格格不入。尝试过很多种方案,都无法真正完美的实现无边框方案,最近看到大佬的无边框库,感觉挺好用,于是赶紧编译使用了一下,在此进行记录:qwindowkit地址。
原生QMainWindow:
2、源码下载地址
3、源码cmake编译
Windows: MSVC: 2019, 2022 + Qt 5.12 or higher。直接编译即可。
4、使用方式
效果:
1)在main函数进行如下设定:
QGuiApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
#include "QtWidgetsTest.h"
#include <QtWidgets/QApplication>
#include "QWKWidgets/qwkwidgetsglobal.h"
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
QApplication a(argc, argv);
QtWidgetsTest w;
w.show();
return a.exec();
}
2)在Mainwindow函数进行如下设定:
windowAgent = new QWK::WidgetWindowAgent(this);
windowAgent->setup(this);
auto windowBar = new QWK::WindowBar();
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);