简体   繁体   English

QWidget / QWindow标题栏:自定义外观,原生感(类似于Chrome)

[英]QWidget / QWindow title bar: custom look, native feel (similar to Chrome)

I know how to make a QWidget (in Qt4 or Qt5) / QWindow (since Qt5) borderless, draw a custom title bar and manually implement mouse dragging to move the window on the screen by simply tracking the mouse position with some mouseMoveEvent and updating the window position. 我知道如何制作一个QWidget(在Qt4或Qt5中)/ QWindow(从Qt5开始)无边界,绘制一个自定义标题栏并手动实现鼠标拖动,通过一些mouseMoveEvent跟踪鼠标位置并更新窗口位置。

However, this movement behaves different than the native one as implemented by the window manager. 但是,此移动的行为与窗口管理器实现的移动行为不同。 For example, moving the window near the screen's border can be interpreted as "fullscreen" or "split screen"; 例如,在屏幕边框附近移动窗口可以解释为“全屏”或“分屏”; or windows snap to each other's borders, depending on the system / window manager. 或Windows与对方的边框对齐,具体取决于系统/窗口管理器。 These things don't work if you implement the window movement like above. 如果您实现上面的窗口移动,这些东西不起作用。

Google Chrome / Chromium is only one example for an application which implements a custom window title bar and border, while still adapting to the native behavior of the window manager. Google Chrome / Chromium只是实现自定义窗口标题栏和边框的应用程序的一个示例,同时仍适应窗口管理器的本机行为。 I'm wondering whether Chrome implements these by itself (and detects the window manager and its configuration) or if there is some functionality in most window managers (clearly, this is still highly platform-dependent) for telling "start native window movement" and "stop native window movement" or similar. 我想知道Chrome是否自己实现这些(并检测窗口管理器及其配置),或者大多数窗口管理器中是否有某些功能(显然,这仍然是高度依赖于平台的),用于告诉“启动本机窗口移动”和“停止原生窗口运动”或类似。

Is something like that possible in Qt? Qt中有类似的东西吗? If not, maybe using some other libraries like Qxt? 如果没有,也许使用像Qxt这样的其他库?

FYI: I'm mainly targeting Windows and Linux, where I see the difficulty that the user can have any window manager installed. 仅供参考:我主要针对Windows和Linux,在那里我看到用户可以安装任何窗口管理器的困难。

Based on attempting the same with Qt4 recently, I fear the answer is, you need to tune this per-platform / per-window-manager. 基于最近对Qt4的尝试,我担心答案是,你需要调整每个平台/每个窗口管理器。 I expect patches to QWindow to improve the behaviour in this area would be accepted, but I'm not aware of any standard hook to tell the OS/window-manager what you're trying to achieve. 我希望QWindow的补丁能够改善这个领域的行为,但是我不知道有任何标准的钩子来告诉操作系统/窗口管理器你想要实现的目标。

Equally Qt should be not be 'getting in the way' of solving this, it's simply an area where it can't do anything to help you in a generic way. 同样Qt应该不会“妨碍”解决这个问题,它只是一个无法以通用方式帮助你的任何事情的领域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM