stdware / qwindowkit Goto Github PK
View Code? Open in Web Editor NEWCross-platform frameless window framework for Qt. Support Windows, macOS, Linux.
License: Apache License 2.0
Cross-platform frameless window framework for Qt. Support Windows, macOS, Linux.
License: Apache License 2.0
qwindowkit 目前支持 Linux 吗?没有看到 Linux 相关的代码
问题描述:
将鼠标停留在窗口边缘指针变成可拖动模式后,按住左键拖动改变窗口大小,此时VS输出窗口大量显示“参数错误”的信息,淹没其他输出日志,导致没法调试程序。
输出信息如下:
17:04:43:193 clientcore\windows\dwm\dwmapi\attribute.cpp(135)\dwmapi.dll!00007FF862104B63: (caller: 00007FFFF4CC4D59) ReturnHr(1) tid(3adc) 80070057 参数错误。
...
17:04:48:698 clientcore\windows\dwm\dwmapi\attribute.cpp(135)\dwmapi.dll!00007FF862104B63: (caller: 00007FFFF4CC4D59) ReturnHr(74) tid(3adc) 80070057 参数错误。
开发环境如下:
Micrisoft Windows 10 LTSC 企业版21H2(内部版本号19044.3930)
Microsoft Visual Studio Community 2022 (64 位) 版本 17.8.6
Qt Visual Studio Tools 版本3.1.0.2
Vcpkg 版本 2023-11-16-4c1df40a3c5c5e18de299a99e9accb03c2a82e1e
qtbase:x64-windows 版本6.5.3
源代码如下:
QtWidgetsDemo.zip
源代码说明(为了定位问题精简剩下3个文件):
main.cpp:
#include <QtWidgets/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[]) {
qputenv("QT_WIN_DEBUG_CONSOLE", "attach");
qputenv("QSG_INFO", "1");
#if 0
qputenv("QT_WIDGETS_RHI", "1");
qputenv("QSG_RHI_BACKEND", "d3d12");
qputenv("QSG_RHI_HDR", "scrgb");
qputenv("QT_QPA_DISABLE_REDIRECTION_SURFACE", "1");QGuiApplication::setHighDpiScaleFactorRoundingPolicy( Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
QApplication a(argc, argv);
#if 0 && defined(Q_OS_WINDOWS) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QApplication::setFont( {
QFont f("Microsoft YaHei");
f.setStyleStrategy(QFont::PreferAntialias);
f.setPixelSize(15);
return f;
}());
#endifMainWindow w; w.show(); return a.exec();
}
mainwindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QtWidgets/QMainWindow>
namespace QWK {
class WidgetWindowAgent;
}class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;private:
QWK::WidgetWindowAgent *windowAgent;
};#endif // MAINWINDOW_H
mainwindow.cpp:
#include "mainwindow.h"
#include <QWKWidgets/widgetwindowagent.h>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
windowAgent = new QWK::WidgetWindowAgent(this); windowAgent->setup(this); resize(800, 600);
}
MainWindow::~MainWindow() = default;
当前 WidgetWindowAgent 仅仅只是一个代理。它没有默认的窗口标题栏。如果用来修改原来的代码。工程量很大。
建议增加默认标题栏。它的要求如下:
实现:建议用 WidgetWindowAgent 派生类实现。
I have both qt5 and qt6 installed on linux.
For me this https://github.com/stdware/qwindowkit/blob/main/src/QWindowKitConfig.cmake.in ends up choosing Qt5, which causes issues down the line when trying to link to it, since the rest of my application is Qt6 > Qt5
, basically Qt5 is just a fallback in case Qt6 is not found.
My current fix is to set set(QMSETUP_FIND_QT_ORDER Qt6)
manually.
Would it be possible to default to Qt6?
Thanks
环境:Qt6.5.3 msvc2019
系统:windows11
现象:
1、非最大化情况下QStatusBar没有立即显示,要经过一次resize才能显示
2、最大化后QStatusBar没有显示,此时无法resize因此无法让其显示出来
好像换成了 agent->setTiltBar()
? 希望作者大大可以更新一下
#include <windows.h>
#include <dwmapi.h>
MyWidget::MyWidget(QWidget *parent) : QWidget(parent) {
const auto hwnd = reinterpret_cast<HWND>(winId());
// We need to extend the window frame into the whole client area to be able to see the blurred window background.
const auto margins = MARGINS{ -1, -1, -1, -1 };
::DwmExtendFrameIntoClientArea(hwnd, &margins);
// Use official DWM API to enable Mica/Mica Alt, available since Windows 11 (10.0.22000).
const DWM_SYSTEMBACKDROP_TYPE blurType = DWMSBT_MAINWINDOW; // This one is Mica, if you want to enable Mica Alt, use DWMSBT_TABBEDWINDOW instead.
::DwmSetWindowAttribute(hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &blurType, sizeof(blurType));
}
References:
What I want is that we can resize the window programmatically, but disable user to resize window by dragging borders.
In previous project , I find that setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) works as isWidgetFixedSize(in framelesswidgetshelper.cpp line 133) takes sizePolicy into account.
But in current project, the feature disappears, and I don't know how to modify code to achieve the same functionality.
Can you restore the logic of FramelessHelper or tell me another way to do it?
Thanks for reading and hope for your reply!
cmake -B build -S . -G "Visual Studio 17 2022" -T host=x64 -A win32
[cmake] -- Building qmsetup (Release)...
[cmake] -- Installing qmsetup (Release)...
[cmake] CMake Error at CMakeLists.txt:68 (find_package):
[cmake] Could not find a configuration file for package "qmsetup" that is
[cmake] compatible with requested version "".
[cmake]
[cmake] The following configuration files were considered but not accepted:
[cmake]
[cmake] D:/C++_Study/GUI/qwindowkit/build/_install/lib/cmake/qmsetup/qmsetupConfig.cmake, version: 0.0.1.5 (64bit)
[cmake]
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
First of all let me say that this might or might not be a bug, let me explain.
I used to save the geometry of my MainWindow in hideEvent
and restore it (setGeometry
) in showEvent
with FramelessHelper and that used to work flawlessly.
When using qwindowkit however, restoring the geometry in showEvent
doesnt work anymore. I have to set it again, after mainWindow->show();
is called.
Before with FramelessHelper:
class MainWindow
{
void hideEvent(QHideEvent* event)
{
// save geometry
}
void showEvent(QShowEvent* event)
{
// restore geometry
}
};
MainWindow* main = new MainWindow();
main->show();
Now with qwindowkit:
class MainWindow
{
void hideEvent(QHideEvent* event)
{
// save geometry
}
void showEvent(QShowEvent* event)
{
// restore geometry - DOESNT WORK
}
};
MainWindow* main = new MainWindow();
main->show();
main->setGeometry(geo); // HAVE TO DO IT HERE NOW
Framelesshelper used to have it, why is it gone?
The windows-app usually restore original window focus.
Platform: seems to only occur on Windows 10 (22H2-19045.3803) and with ENABLE_WINDOWS_SYSTEM_BORDERS off
Steps to reproduce:
Note: resizing the app will correct the sizing issue, moving it again will reintroduce it.
Accepting the WM_MOVE event in WindowsNativeEventFilter::nativeEventFilter
seems to prevent this from occurring, but I have no idea why or what side effects it introduces.
步骤
1、管理员打开x64_x86 Cross Tools Command Prompt for VS 2019
2、git clone --recursive https://github.com/stdware/qwindowkit
3、cd qwindowkit
4、cmake -B build -S . -Dqmsetup_DIR=E:/Develop/2019/QWindowKit/qmsetup -DCMAKE_INSTALL_PREFIX=E:/Develop/2019/QWindowKit -G "Visual Studio 16 2019" -A Win32
提示
E:\Develop\2019\QWindowKit>cmake -B build -S . -Dqmsetup_DIR=E:/Develop/2019/QWindowKit/qmsetup -DCMAKE_INSTALL_PREFIX=E:/Develop/2019/QWindowKit -G "Visual Studio 16 2019" -A Win32
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
-- The CXX compiler identification is MSVC 19.29.30147.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring qmsetup...
-- Building qmsetup (Release)...
-- Installing qmsetup (Release)...
CMake Error at CMakeLists.txt:68 (find_package):
Could not find a configuration file for package "qmsetup" that is
compatible with requested version "".
The following configuration files were considered but not accepted:
E:/Develop/2019/QWindowKit/build/_install/lib/cmake/qmsetup/qmsetupConfig.cmake, version: 0.0.1.5 (64bit)
不加-A Win32没问题
在win上实现圆角的dialog
我用Qt::FramelessWindowHint特性,然后自己绘制阴影和背景,虽然可以实现,但是原来系统自带的效果(如:点击窗口外部,弹窗阴影闪烁)没有了,我希望在保留系统特性的情况下,实现圆角dialog
大佬无边框窗口设置Qt::WindowStaysOnTopHint表现不正常
MacOS下,我有一个带有QWK::WidgetWindowAgent代理的窗口A,在其中再创建一个带有代理的窗口B。销毁窗口B的时候,会crash。
代码如下:
WinKitTest::WinKitTest(QWidget *parent)
: QWidget(parent)
, ui(new Ui::WinKitTest)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
// frameless agent
m_windowAgent = new QWK::WidgetWindowAgent(this);
m_windowAgent->setup(this);
m_windowAgent->setTitleBar(ui->label);
m_windowAgent->setSystemButton(QWK::WindowAgentBase::Close, ui->pushButton);
m_windowAgent->setHitTestVisible(ui->pushButton_2);
}
WinKitTest::~WinKitTest()
{
delete ui;
qDebug() << "DDDDDDDDDDDDDD";
}
void WinKitTest::on_pushButton_2_clicked()
{
(new WinKitTest())->show();
}
void WinKitTest::on_pushButton_clicked()
{
close();
}
按下pushButton_2创建一个新的WinKitTest。
按下新的WinKitTest中的pushButton,程序就崩溃了。
堆栈如图:
尊敬的作者,您好,
目前测试Qt5.12.10 + VS2019编译出错,
1, 缺少头文件<QtCore/private/qwinregistry_p.h>
, 这个我找了一下,确实5.12没有这个文件
2,缺少Q_DISABLE_COPY_MOVE
这个宏
操作系统:Win10 22H2
Qt版本:6.7.0
使用如下代码测试:
import QtQuick
import QtQuick.Window
import QtQuick.Controls
import Qt.labs.platform
import QWindowKit
Window {
id: window
width: 800
height: 600
title: qsTr("Hello, world!")
Component.onCompleted: {
windowAgent.setup(window)
window.visible = true
}
WindowAgent {
id: windowAgent
}
MouseArea{
anchors.fill: parent
onPressed: (mouse)=>{
var global = mapToGlobal(mouse.x,mouse.y)
helper.setCursorPos(global.x,global.y)
var local = mapFromGlobal(global.x,global.y)
console.log("mouse:",mouse.x,mouse.y," global:",global," local:",local)
}
}
helper.setCursorPos(global.x,global.y) 是一个C++提供的函数,它仅仅是调用QCursor::setPos(x, y)
目前发现开启无边框窗口后,mapToGlobal得到的鼠标位置跟实际的鼠标位置会相差一个标题栏的高度,但是再使用mapFromGlobal还原得到的本地坐标确实正确的
在QML模式中拖动标题栏会使窗口内的控件错位,应该刚好错位一个标题栏的高度。
另外如果设置qputenv("QSG_RHI_BACKEND", "opengl");
的话会使标题栏的y坐标变为负数,也就是在窗口外面。
Text {
anchors {
bottom: parent.bottom
bottomMargin: 32
left: parent.left
}
font {
pointSize: 14
bold: true
}
color: "#ECECEC"
text: 'test'
}
In my program, I use QuarterWidget (which extends QGLWidget) in Coin3D to draw 3D models.
So I test QGLWidget in QWKExample_MainWindow when it's needed to import QWK.
Replace the ClockWidget with QGLWidget, a display error occurred.
Drag window to another screen, the display error disappears, but the window can never be movable by dragging in TitleBar.
setAttribute(Qt::WA_NativeWindow,false) could fix the problem. But the attribute is necessary for QGLWidget.
P.S. Can you provide apis to specify whether the window can be resizable by dragging borders and if so, the margin can also be customized (as it's 2px hard-coded now)?
Thanks for reading and hope your replys!
If I do put
qputenv("QSG_RHI_BACKEND", "d3d12");
and run QML example the window background is always black, no matter what "Special effect" I choose.
Windows 11, Qt 6.6.1 or 6.5.2, MSVC2019, latest nVidia drivers installed. Setting QSG_RHI_BACKEND
to opengl
solves the problem, but opengl is laggy by itself so supporting DirectX would be great. Is it a bug, or an unsupported feature?
当我将qwindowkit作为子项目并链接时,发生错误
export called with target "XXXX" which requires target "QWKWidgets"
that is not in any export set.
1、修改标题栏高度:
在创建标题栏时,设置固定高度即可
windowBar->setFixedHeight(40);
2、修改三个系统按钮位置:
windowAgent->setSystemButtonAreaCallback([](const QSize &size) {
static constexpr const int width = 75;
return QRect(QPoint(size.width() - width, 0), QSize(width, size.height()));
});
针对这段代码,我改为return QRect(QPoint(size.width() - width, 10), QSize(width, size.height())); y向偏移了,但是无效。
是的还有其他需要设置?
相关qml设置如下:
ApplicationWindow {
id: window
visible: false // We hide it first, so we can move the window to our desired position silently.
minimumHeight: 1080
minimumWidth: 1920
width: 1920
height: 1080
屏幕大小:1920x1080
之前没有问题,打开程序后,程序窗口是靠紧屏幕左边的。
前几天更新代码库后,发现,程序启动后,屏幕左边会空白几个像素的空白,不确定是否是最近的代码更新造成的。
如下图(最左边边缘一条蓝色的是屏幕左边背景蓝色,请点开图片查看,看缩略图看不出来。):
举例:
我有个库A引用qwindowkit
target_link_libraries(A PUBLIC
QWindowKit::Core
)
此时构建是没有任何问题的。
但是当按照
https://cmake-doc.readthedocs.io/zh-cn/latest/guide/importing-exporting/index.html
进行导出安装后
install()...
install()...
export(EXPORT ATargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/Aargets.cmake"
NAMESPACE ${NAMESPACE}::
)
关键是使用export之后
在生成阶段会报错:
export called with target "A" which requires target "QWKCore" that is
not in any export set.
我需要使用export()使A在构建树中的其他项目可见
当调用close()关闭窗口后,重新显示时标题栏将无法拖动,不知道是否是特性还是bug。
测试方式:
使用QWKExample_MainWindow项目进行测试
修改代码如下:
MainWindow w;
//w.show();
QPushButton button;
QObject::connect(&button, &QPushButton::clicked, [&w] { w.show(); });
button.show();
return a.exec();
我的qt版本6.5.2 vs2022
经过测试
framelesshelper也存在相同的问题
Setting up a Quick application with QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL)
causes some issues with the title bar. I have observed the following:
I presume it is not actually invisible, just somewhere out of sight further up, since content that is anchored to the title bar gets shifted upwards when the bar is not visible.
OS: Windows 10 Pro (22H2, Build 19045.3803)
Qt: 6.5.3
你好,我尝试用qt5.14msvc2017编译时发现如下问题:
1、“starts_with”: 不是string的成员
qmsetup需要c++20版本支持starts_with是cpp20才加入的
qwindowkit\qmsetup\src\corecmd\main.cpp(229): error C2039: “starts_with”: 不是“std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>”的成员
2、“max”: 不是“std”的成员
qwindowkit\qmsetup\src\syscmdline\src\helplayout.cpp(60): error C2039: “max”: 不是“std”的成员
qwindowkit\qmsetup\src\syscmdline\src\parseresult.cpp(179): error C2039: “max”: 不是“std”的成员
helplayout.cpp
和parseresult.cpp
加上algorithm头文件即可#include <algorithm>
这是提示的日志文件
qmsetup_build-Release.log
作者您好,之前 framelesshelper 提供的 Utils::shouldUseDarkTheme()
被移除了,好像 qwindowkit
没有提供相同功能的接口,是否有考虑把这个接口加回来呢?
After adding a QVideoWidget object to the QWKExample_MainWindow project, I encountered an issue where clicking and dragging the title bar does not move the window. The code is as follows:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), m_videoWidget(new QVideoWidget(this)), m_player(new QMediaPlayer(this)) {
installWindowAgent();
//auto clockWidget = new ClockWidget();
//clockWidget->setObjectName(QStringLiteral("clock-widget"));
//clockWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
//setCentralWidget(clockWidget);
setCentralWidget(m_videoWidget);
m_player->setVideoOutput(m_videoWidget);
loadStyleSheet(Dark);
setWindowTitle(tr("Example MainWindow"));
resize(800, 600);
}
After invoking the QMediaPlayer::setVideoOutput interface, there are issues with the window's title bar area, as well as problems with window rendering. However, if you resize the window vertically by dragging the top or bottom borders, the mouse can once again move the window by dragging the title bar area. I encountered the same issue with a simple custom frameless window implementation I had developed earlier. I haven't identified the specific cause yet and hope you can provide a solution.
环境: win11 Qt5.12.2 MSVC2017
编译报错:
windowagentbase.cpp.obj : error LNK2019: 无法解析的外部符号 "public: __cdecl QWK::QtWindowContext::QtWindowContext(void)" (??0QtWindowContext@QWK@@qeaa@XZ),该符号在函数 "public: virtual class QWK::AbstractWindowContext * __cdecl QWK::WindowAgentBasePrivate::createContext(void)const " (?createContext@WindowAgentBasePrivate@QWK@@UEBAPEAVAbstractWindowContext@2@XZ) 中被引用
out-amd64-Release\bin\QWKCore.dll : fatal error LNK1120: 1 个无法解析的外部命令
OS: Windows 11
Qt: 6.5.3
UI Framework: QML, Quick
Build command: cmake -B build -DCMAKE_INSTALL_PREFIX=[hidden] -G "Ninja Multi-Config" -DQT_DIR=[hidden] -DQWINDOWKIT_BUILD_QUICK=ON -DQWINDOWKIT_ENABLE_WINDOWS_SYSTEM_BORDERS=OFF
When resizing the Window using the top/left edges part of the bottom client area extends to far into the bottom, resulting in a part being hidden. This also happens when moving the window using the title bar. When starting the application using the suggested method, the window starts in this broken state. Using the bottom/right edges to resize fixes this problem.
EDIT: While the window is maximized the right side is also affected, part of the clientarea extends too far towards the right and is hidden.
I made an example app demonstrating this. The numbers 1-20 should be fully visible, but as you can see even the 19 is only half visible.
PySide2是对Qt的封装,该项目是否有支持Pyside2的计划,或者有没有什么建议。
[ 45%] Linking CXX shared library ../../out-arm64-/lib/libQWKCore.dylib
ld:` warning: ignoring file '/Users/user/Qt5.14.2/5.14.2/clang_64/lib/QtGui.framework/Versions/5/QtGui': found architecture 'x86_64', required architecture 'arm64'
你好,请问报这个错误是咋回事啊?我按照readme中的步骤来构建。系统是macos 13.5,芯片是apple m2 pro。
提前谢谢了
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/toolchain/7.5.0/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at src/syscmdline/CMakeLists.txt:74 (target_compile_features):
target_compile_features The compiler feature "cxx_std_20" is not known to
CXX compiler
"GNU"
version 7.5.0.
CMake Error at src/corecmd/CMakeLists.txt:25 (target_compile_features):
target_compile_features The compiler feature "cxx_std_20" is not known to
CXX compiler
"GNU"
version 7.5.0.
-- Configuring incomplete, errors occurred!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.