Comments (32)
今天我写了一个新的类,能直接在QML文件里调用,完全不涉及C++,由于是对WinNativeEventFilter
的简单封装,因此代码不多,很快就写完了,测了下效果不错,但在测试的时候发现了原来的代码有些bug,正在调试。调试完了我把新代码传上来。
from framelesshelper.
理论上只要你能拿到对应窗口的句柄,然后对其调用addFramelessWindow
就可以让它无边框,但我也是搞Qt Quick开发的,我最早测试的就是这种用QQmlApplicationEngine
加载QML文件的方案,遗憾的是,通过这种方式加载的QML,只要调用那个接口,对应的窗口就会完全消失,调用show
也不能使其再次显示出来,原因暂时未知。
因为一直都解决不了这个问题,所以这个项目一开始一直都没有Qt Quick的例子,后来突然发现使用QQuickView
加载QML不存在这个问题,这才把Qt Quick的例子加上了。由于使用QQuickView
确实有诸多不便之处,很多相关函数都要自己重新封装,所以我也不是很喜欢用这个类,但只要我提到的那个问题解决不了,就没办法。
但这只是我自己的情况,你也可以自己试试,看看情况具体是怎样。
from framelesshelper.
你也可以试试FramelessHelper
这个类,这个类用的是纯Qt API,不涉及平台,大概不会有这种奇怪问题,但使用这个类要求Qt版本不能低于5.15,而且在Windows上效果也不如WinNativeEventFilter
from framelesshelper.
那个bug解决了。
我还是那句话,只要你能拿到对应的QWindow,就能让它无边框。这部分内容就不是这个无边框代码该考虑的事情了。一个Window就对应着一个QWindow?不太清楚,你根据objectName获取一下这些Window,然后转换成QWindow试试。
from framelesshelper.
试了试,在QML中这样操作确实比较麻烦,我会再新增一个类,专门在QML里用,这样能方便点。之前因为那个bug没解决,所以一直搁置了这个计划,现在能做了。
from framelesshelper.
如果是在c++里面拿到qml中的QWindow 句柄,执行addFramelessWindow之后就可以使用的话,已经很方便了。
from framelesshelper.
好的,期待中,如果那样就更方便了
from framelesshelper.
我这边遇到的问题是,我要拿到QQuickItem的坐标,但直接获取的坐标是相对于其父对象的,我这边要用的是相对于这个窗口的坐标,我用mapToScene转换了一下,发现转换后坐标有偏移,两个QQuickItem之间的间隔是45像素,但转换后就变成90像素了,但我开的也不是200%的缩放,所以不明白原因。这个问题你有什么头绪吗?
from framelesshelper.
item 和window不是父子关系,但是想获取item相对于window的坐标吗
from framelesshelper.
不是直接的父子关系(中间隔了些东西),但想获取相对于window的坐标,不是相对于屏幕的坐标
from framelesshelper.
我试了试,不管是mapToScene还是mapToGlobal,都会把本来是45像素的间距,变成90,就算是DPI缩放,这个缩放的比例也不对
from framelesshelper.
我试试,这个问题我也没遇到过
from framelesshelper.
新发现,用mapFromScene({0, 0})获取的坐标是对的,只不过都是负数
from framelesshelper.
from framelesshelper.
十分感谢!看来我还是对Qt Quick不够熟悉啊。
你可以试试我新增的FramelessQuickHelper
,具体用法看示例工程就可以了,用法很简单。用这个可以不用再去搞什么QWindow了,应该能方便很多。
from framelesshelper.
我试了一下,可以正常使用,想问一个别的问题,你对qml中的webengineView熟悉吗,什么情况下会影响它的cpu和gpu使用率,我现在不自定义窗口的话,使用最原始的window,打开相同页面资源利用率和chrome差不多,自定义窗口后,打开相同页面,gpu占用率会多%10左右。好奇怪。
from framelesshelper.
什么叫“自定义窗口”?
from framelesshelper.
webcontainer.qml
`import QtQuick 2.12
import QtQuick.Window 2.12
import QtWebEngine 1.9
import QtQuick.Layouts 1.11
import QtWebChannel 1.13
import WebDataComponent 1.0
WebEngineView {
id: pluginWebContainer
settings.autoLoadImages: true
settings.javascriptEnabled: true
settings.errorPageEnabled: true
settings.pluginsEnabled: true
settings.fullScreenSupportEnabled: true
settings.autoLoadIconsForPage: true
settings.touchIconsEnabled: false
settings.webRTCPublicInterfacesOnly: false
settings.pdfViewerEnabled: true
onCertificateError: function(error) {
error.defer();
sslDialog.enqueue(error);
}
webChannel: WebChannel{
registeredObjects: [_WebDataComponent]
}
WebDataComponent{
id:_WebDataComponent
WebChannel.id:"bdlbscWebDataComponent"
}
}`
情况一
`import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.13
import wangwenx190.Utils 1.0
import "./app"
Window {
visible: true
x:400
y: 150
width: 1022
height: 672
minimumWidth: 650
flags: Qt.Window
WebContainer{
url:"https://www.bilibili.com"
anchors.fill:parent
}
}`
情况二
`import QtQuick 2.12
import QtQuick.Window 2.12
import wangwenx190.Utils 1.0
import "./component"
import "./app"
Window {
id: root
visible: true
width: 800
height: 600
title: qsTr("Hello, World!")
FramelessHelper {
id: framelessHelper
Component.onCompleted: framelessHelper.removeWindowFrame()
}
Rectangle {
id: titleBar
height: 30
color: "white"
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
Text {
id: titleBarText
text: root.title
font.family: "Noto Sans CJK SC"
font.pointSize: 13
color: "black"
anchors.left: parent.left
anchors.leftMargin: 15
anchors.verticalCenter: parent.verticalCenter
}
Row {
anchors.top: parent.top
anchors.right: parent.right
ZButton{
label.text: "-"
id: minimizeButton
onClicked: root.showMinimized()
Component.onCompleted: framelessHelper.addIgnoreObject(
minimizeButton)
}
ZButton {
label.text: "口"
id: maximizeButton
// QWindow::Visibility::Maximized
onClicked: {
if (root.visibility == 4) {
root.showNormal()
} else {
root.showMaximized()
}
}
Component.onCompleted: framelessHelper.addIgnoreObject(
maximizeButton)
}
ZButton {
label.text: "x"
id: closeButton
onClicked: root.close()
Component.onCompleted: framelessHelper.addIgnoreObject(
closeButton)
}
}
}
WebContainer{
anchors.fill: parent
url: "https://www.bilibili.com"
}
}`
情况一的资源占用率和chrome差不多,情况二的gpu占用率会多%10左右。
from framelesshelper.
明白了,你的意思是用了我的代码后,GPU占用率会有明显的上升?
from framelesshelper.
之前我的代码资源占用率就有点高,所以也一直在解决这个问题,只是这样做了一个对比,我就是不知道什么会影响webengineview 的资源占用率
from framelesshelper.
如果你能确定在用了我的代码后GPU占用率有明显升高,你可以尝试把WinNativeEventFilter中的m_lpSetWindowLongPtrW(msg->hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYERED);
这一行以及它下面的那一行都注释掉,再去看看GPU占用率。我的代码中,唯一能影响性能的代码,只有这个地方。
关于如何优化webengineview的资源占用率,我不是很熟悉,没法帮你了。
from framelesshelper.
注释了之后有很大改善,可以满足要求了。
from framelesshelper.
还有一个小问题,怎么设置窗口缩放最小允许的width和height。
from framelesshelper.
注释了之后有很大改善,可以满足要求了。
没有那一部分代码,调整窗口大小时可能会有比较明显的闪烁现象(Qt Widgets和Qt Quick程序都会如此),如果能接受倒也无所谓。
还有一个小问题,怎么设置窗口缩放最小允许的width和height。
刚才把接口加上了,用法很简单:
FramelessHelper {
minimumSize: "200x100"
maximumSize: "800x600"
}
还有wangwenx190.Utils
这个名字,是我在示例工程里随便设置的,如果你要在自己的项目里用,可以改成别的。
from framelesshelper.
好的。简直完美。
from framelesshelper.
如果你那边确定要用这个代码的话,我希望有机会的话你能提供一些软件运行时的截图,我这边可以放在自述文件里展示。不过你不愿意或者不方便就算了。
from framelesshelper.
from framelesshelper.
看起来很棒,但这个用了这个repo吗?
from framelesshelper.
用了的。我是直接把那几个源文件放到我的项目里了。改造了我之前写的window窗体。
from framelesshelper.
行,能帮上你的忙我也很高兴。我打算把这张截图放到自述文件中作展示用,可以吗?
from framelesshelper.
可以,随便用。
from framelesshelper.
好的,那就多谢了。
from framelesshelper.
Related Issues (20)
- Global::Option::ForceHideWindowFrameBorder causes the frame border to be weird on Windows HOT 10
- 请教关于Qmainwindow的布局问题 HOT 4
- 编译问题 HOT 2
- Qt 6.6.0 Windows Unable to set geometry Issue HOT 3
- qt 6.5.3 窗口拖动改变大小时控件位置不正确 HOT 6
- ubuntu linux下用qt5.15.2版本编译报错
- MacOS最后一个窗口销毁再新建窗口崩溃分析反馈,窗口全屏状态修改分辨率异常问题求助 HOT 5
- Unable to restore window state after minimizing it when using the ApplicationWindow component from Qt controls HOT 3
- Windows下标题栏按钮tooltip重复显示 HOT 3
- closeEvent事件,对QCloseEvent事件进行ignore后,原来无边框的窗体会出现边框 HOT 2
- 把Q_OBJECT包裹在其它宏里面后,qmake编译失败 HOT 1
- quick 最小化问题
- Build error macOS HOT 1
- Build error in apple M1, when Qt is not a universal version.
- 苹果M芯片编译错误 HOT 1
- Win11 5.15.2 main 分支下的 版本
- QOpenGLFunctions 自定义控件显示问题
- 【bug】windows10下最大化和恢复按钮不显示
- 使用 QWebEngineView 之后标题栏按钮无法交互 HOT 18
- 代码问题 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from framelesshelper.