Giter Site home page Giter Site logo

qt-framelesswindow's Introduction

>>> 中文版

1. FramelessWindow

When I started using Qt as UI library, I found that Qt didn't provide a perfect borderless window solution to support the following functions, and I have to implement these functions by myself:

  1. Support to change the position and size of the window by dragging the mouse; ✅
  2. Support double-click the title bar to maximize/restore the window; ✅
  3. Support Windows Areo Snap feature;
  4. Support system shadow;
  5. Support dragging across screens that have different DPI; ✅
  6. Automatically adapt to changes in resolution and DPI; ✅

2. Implementation scheme comparison

There are two schemes for implementing borderless windows in Qt.

2.1 Scheme 1

By overriding nativeEvent function to hook windows message(such as 'WM_NCHITTEST`), the general steps are as follows:

  1. Set the WS_THICKFRAME | WS_CAPTION property to restore the window border and title, so that the window can receive the WM_NCHITTEST message.

  2. Then remove the border and title in the WM_NCCALCSIZE message processing.

  3. Set the mouse behavior (HTLEFT, HTRIGHT, etc.) by judging the mouse position in the WM_NCHITTEST message processing.

The advantage of this solution is that it can support the Windows Areo Snap and System Shodow feature, but it is very complicated for message processing and needs to be compatible with various versions of Qt. At present, I have not found a solution to achieve a perfect borderless through this solution.

As far as I know, the following open source projects are implemented in this way, but there are some problems, such as not supporting drag across screens that have different DPI screens, unable to adapt to resolution and DPI changes, and WM_NCHITTEST sometimes not responding, etc. In addition, after setting the background transparency property (such as Qt :: WA_TranslucentBackground), the system shadow feature will also disappear.

2.2 Scheme 2

This solution not hook windows WM_NCHITTEST,WM_NCCALCSIZE messages, nor does it change the window style, and is implemented by pure Qt.

By setting MouseTracking for each Widget, make sure each Widget can respond to mouse events (mouseMoveEvent, mousePressEvent, mouseReleaseEvent, etc.), and then determine the mouse position in these events to set the shape and behavior of the mouse.

Although the logic for judging the position of the mouse is cumbersome in this way, the compatibility is better and pure, and it does not need to process various messages of Windows.

👉 This project is implemented in this way, and can support all the features of the borderless form except "Windows Areo Snap" and "System Shadow" features mentioned above.

Screenshot On Windows

screenshot on windows

qt-framelesswindow's People

Contributors

winsoft666 avatar

Watchers

James Cloos avatar

Forkers

15831944

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.