用Qt制作无边框窗口
我是 Qt C++ 新手。我下载了最新的 Windows 版本,做了一些教程,非常棒。
我看到了 Qt 框架具有的一些样式选项,而且它很棒,但现在我需要构建我的应用程序,其主窗口(形式)是用没有矩形边框(无边框?)的图像设计/蒙皮的。
我怎样才能用Qt做到这一点?
I'm new to Qt C++. I downloaded the latest windows version, did some tutorials and its great.
I saw some styling options that the Qt framework has and its great, but now I need to build my application that its main windows (form) it designed/skinned with image without the rectangle borders (borderless?).
How can I do it with Qt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您正在寻找小部件形状的一些高级样式,也许这个示例会对您有所帮助:
形状时钟示例
或者您可能只是在寻找这种标志:
Qt::CustomizeWindowHint
或只是Qt::FramelessWindowHint
。If your looking for some advanced styling in the shape of a widget, maybe this example will help you:
Shaped Clock Example
Or maybe you're simply looking for this kind of flag:
Qt::CustomizeWindowHint
or simplyQt::FramelessWindowHint
.我创建了一个小例子,说明如何在 Qt5 中创建类似 VS2013 的无框窗口:
您可以在这里获取完整的源代码:https ://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle
另外,这里是如何将“主”主窗口嵌入到“无框架”窗口中的代码概述。您还可以了解如何添加标题栏、按钮以及如何最大化、调整大小和移动无框窗口。
mainwindow.h
mainwindow.cpp
I created a small example, of how to create VS2013 like frameless window in Qt5:
You can get the complete sources here: https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle
Otherwise here a code overview of how to embed the "main" mainwindow into the "frameless" window. Also you can see how to add titlebar, buttons and do maximize, resize and move of the frameless window.
mainwindow.h
mainwindow.cpp
您的 Qt 目录中有一个示例应用程序:
examples/小部件/windowsflags
。There is a sample application in your Qt directory:
examples/widgets/windowsflags
.我自己也遇到过这个问题,并在一段时间后弄清楚了。查看 https://github.com/ianbannerman/TrueFramelessWindow 以获取适用于 Windows 和 Windows 的示例代码。 macOS。
Qt::FramelessWindowHint 牺牲了调整大小和最小/最大/关闭,因此可能不是大多数人正在寻找的。
I ran into this myself and figured it out after some time. Check out https://github.com/ianbannerman/TrueFramelessWindow for sample code for both Windows & macOS.
Qt::FramelessWindowHint sacrifices resizing and min/max/close, so is probably not what mot people are looking for.