├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── publish.yml ├── .gitignore ├── LICENSE ├── README.md ├── docs ├── Makefile ├── make.bat ├── requirements.txt └── source │ ├── _static │ ├── Alpha-Gobang-Zero.jpg │ ├── Groove.jpg │ ├── PyQt-Fluent-Widgets.jpg │ ├── PyQt-Fluent-Widgets.png │ ├── acrylic_window.jpg │ ├── cover.jpg │ ├── geometry.png │ ├── logo.png │ ├── snap_layout.png │ └── title_bar_margin.png │ ├── conf.py │ ├── index.rst │ ├── quick-start.md │ ├── see-also.md │ ├── snap-layout.md │ ├── usage.md │ └── window-effect.md ├── examples ├── acrylic_demo.py ├── demo.py ├── main_window.py ├── screen_capture_filter.py └── web_engine.py ├── qframelesswindow ├── __init__.py ├── _rc │ ├── __init__.py │ ├── resource.py │ ├── resource.qrc │ └── title_bar │ │ └── close.svg ├── linux │ ├── __init__.py │ └── window_effect.py ├── mac │ ├── __init__.py │ └── window_effect.py ├── titlebar │ ├── __init__.py │ └── title_bar_buttons.py ├── utils │ ├── __init__.py │ ├── linux_utils.py │ ├── mac_utils.py │ └── win32_utils.py ├── webengine │ └── __init__.py └── windows │ ├── __init__.py │ ├── c_structures.py │ └── window_effect.py ├── requirements.txt ├── screenshot ├── acrylic_window.jpg ├── cover.jpg ├── logo.png ├── normal_frameless_window.gif └── shoko.png └── setup.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: zhiyiYo 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: ['https://afdian.com/a/zhiyiYo'] 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | 18 | 19 | **Describe the bug** 20 | A clear and concise description of what the bug is. 21 | 问题的简要描述。 22 | 23 | **Environment** 24 | 环境信息 25 | - OS: [e.g. Windows10] 26 | - DPI scaling: [e.g. 125%] 27 | - Python: [e.g. 3.8.6 64-bit] 28 | - PyQt5: [e.g. 5.15.2] 29 | 30 | **To Reproduce** 31 | 复现问题的步骤,推荐使用 gif 进行演示。 32 | Steps to reproduce the behavior(you can use GIF to demonstrate :): 33 | 1. Go to '...' 34 | 2. Click on '....' 35 | 3. See error 36 | 37 | **Code** 38 | 最小复现代码 39 | ```python 40 | # Minimum code to reproduce the error 41 | 42 | ``` 43 | 44 | **Expected behavior** 45 | A clear and concise description of what you expected to happen. 46 | 47 | **Screenshots** 48 | If applicable, add screenshots to help explain your problem. 49 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Upload Python Package 2 | 3 | on: workflow_dispatch 4 | 5 | permissions: 6 | contents: read 7 | 8 | jobs: 9 | deploy: 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | branch: [master, PyQt6, Pyside2, PySide6] 14 | 15 | steps: 16 | - name: Checkout branch 17 | uses: actions/checkout@v4 18 | with: 19 | ref: ${{ matrix.branch }} 20 | 21 | - name: Set up Python 22 | uses: actions/setup-python@v3 23 | with: 24 | python-version: '3.8' 25 | 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | pip install build 30 | 31 | - name: Build package 32 | run: python -m build 33 | 34 | - name: Publish package 35 | uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 36 | with: 37 | user: __token__ 38 | password: ${{ secrets.PYPI_API_TOKEN }} 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # 忽略.vscode文件夹 2 | .vscode/ 3 | .VSCodeCounter 4 | 5 | # 忽略工作区文件 6 | *.code-workspace 7 | 8 | # 忽略python缓存文件 9 | */__pycache__ 10 | *.py[cod] 11 | 12 | # 忽略测试文件 13 | test.py 14 | 15 | dist 16 | build 17 | PyQt5_Frameless_Window.egg-info -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | logo 3 |

4 |

5 | PyQt-Frameless-Window 6 |

7 |

8 | A cross-platform frameless window based on PyQt5 9 |

10 | 11 |

12 | 13 | Platform Win32 | Linux | macOS 14 | 15 | 16 | 17 | Download 18 | 19 | 20 | 21 | GPLv3 22 | 23 |

24 | 25 | ![Cover](https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/master/screenshot/cover.jpg) 26 | 27 | 28 | ## Features 29 | * Moving 30 | * Stretching 31 | * Window shadow 32 | * Window animation 33 | * Win11 snap layout 34 | * Win10 acrylic blur 35 | * Win11 mica blur 36 | * Win7 Aero blur 37 | * MacOS blur 38 | * Disable screen capture 39 | 40 | 41 | ## Install 42 | To install use pip: 43 | ```shell 44 | pip install PyQt5-Frameless-Window 45 | ``` 46 | Or clone the repo: 47 | ```shell 48 | git clone https://github.com/zhiyiYo/PyQt-Frameless-Window.git 49 | python setup.py install 50 | ``` 51 | 52 | ## Requirements 53 | 54 | | Platform | Requirement | 55 | | :------: | :---------: | 56 | | Win32 | pywin32 | 57 | | Linux | xcffib | 58 | | MacOS | pyobjc | 59 | 60 | 61 | ## Usage 62 | To use the frameless window, you only need to inherit `FramelessWindow` or `FramelessMainWindow`. Here is a minimal example: 63 | ```python 64 | import sys 65 | 66 | from PyQt5.QtWidgets import QApplication 67 | from qframelesswindow import FramelessWindow 68 | 69 | 70 | class Window(FramelessWindow): 71 | 72 | def __init__(self, parent=None): 73 | super().__init__(parent=parent) 74 | self.setWindowTitle("PyQt-Frameless-Window") 75 | self.titleBar.raise_() 76 | 77 | 78 | if __name__ == '__main__': 79 | app = QApplication(sys.argv) 80 | demo = Window() 81 | demo.show() 82 | sys.exit(app.exec_()) 83 | ``` 84 | For more complex requirements, see [demo.py](https://github.com/zhiyiYo/PyQt-Frameless-Window/blob/master/examples/demo.py) and [main_window.py](https://github.com/zhiyiYo/PyQt-Frameless-Window/blob/master/examples/main_window.py). 85 | 86 | ## Examples 87 | * Normal frameless window 88 | ![Normal Frameless Window](https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/master/screenshot/normal_frameless_window.gif) 89 | * Acrylic frameless window 90 | ![Acrylic Frameless Window](https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/master/screenshot/acrylic_window.jpg) 91 | 92 | 93 | ## Document 94 | Want to know more about PyQt-Frameless-Window? Please read the [help document](https://pyqt-frameless-window.readthedocs.io/) 👈 95 | 96 | 97 | ## Notes 98 | 1. `FramelessWindow` provides a default custom title bar. If you don't like it, just rewrite it as [demo.py](https://github.com/zhiyiYo/PyQt-Frameless-Window/blob/master/examples/demo.py) does. 99 | 100 | 2. Moving the acrylic window on Win10 may get stuck. At present, there is no good solution. Maybe you can disable the acrylic effect when moving the window, but I haven't done this in the source code. 101 | 3. Snap layout is not enabled by default. See [#56](https://github.com/zhiyiYo/PyQt-Frameless-Window/issues/56) to learn how to enable it. 102 | 103 | 4. If you encounter this problem on Windows: 104 | > ImportError: DLL load failed while importing win32api 105 | 106 | see my answer on [stackoverflow](https://stackoverflow.com/questions/58612306/how-to-fix-importerror-dll-load-failed-while-importing-win32api/72488468#72488468) or my [blog](https://www.cnblogs.com/zhiyiYo/p/16340429.html) for the solution. 107 | 108 | 5. If you are using PySide2, PySide6 or PyQt6, you can download the code in [PySide2](https://github.com/zhiyiYo/PyQt-Frameless-Window/tree/Pyside2), [PySide6](https://github.com/zhiyiYo/PyQt-Frameless-Window/tree/PySide6) or [PyQt6](https://github.com/zhiyiYo/PyQt-Frameless-Window/tree/PyQt6) branch. 109 | 110 | ## Support 111 | If this project helps you a lot and you want to support the development and maintenance of this project, feel free to sponsor me via [爱发电](https://afdian.com/a/zhiyiYo) or [ko-fi](https://ko-fi.com/zhiyiYo). Your support is highly appreciated 🥰 112 | 113 | ## See Also 114 | Here are some projects that use PyQt-Frameless-Window: 115 | * [**zhiyiYo/QFluentWidgets**: A fluent design widgets library based on Qt](https://qfluentwidgets.com) 116 | * [**zhiyiYo/Groove**: A cross-platform music player based on PyQt5](https://github.com/zhiyiYo/Groove) 117 | * [**zhiyiYo/Alpha-Gobang-Zero**: A gobang robot based on reinforcement learning](https://github.com/zhiyiYo/Alpha-Gobang-Zero) 118 | 119 | ## Reference 120 | * [**wangwenx190/framelesshelper**: Frameless windows for Qt Widgets and Qt Quick applications. Support Win32, X11, Wayland and macOS](https://github.com/wangwenx190/framelesshelper) 121 | * [**libxcb**: Basic Graphics Programming With The XCB Library](https://www.x.org/releases/X11R7.5/doc/libxcb/tutorial) 122 | 123 | ## License 124 | PyQt-Frameless-Window is licensed under [GPLv3](./LICENSE). 125 | 126 | Copyright © 2021 by zhiyiYo. -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | pywin32==227 ; sys_platform=="win32" 2 | xcffib==0.11.1; sys_platform=="linux" 3 | pyobjc ; sys_platform=="darwin" 4 | PyCocoa ; sys_platform=="darwin" 5 | sphinx-markdown-tables==0.0.17 6 | sphinx-rtd-theme==1.1.1 7 | urllib3<2.0.0 8 | -------------------------------------------------------------------------------- /docs/source/_static/Alpha-Gobang-Zero.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/docs/source/_static/Alpha-Gobang-Zero.jpg -------------------------------------------------------------------------------- /docs/source/_static/Groove.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/docs/source/_static/Groove.jpg -------------------------------------------------------------------------------- /docs/source/_static/PyQt-Fluent-Widgets.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/docs/source/_static/PyQt-Fluent-Widgets.jpg -------------------------------------------------------------------------------- /docs/source/_static/PyQt-Fluent-Widgets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/docs/source/_static/PyQt-Fluent-Widgets.png -------------------------------------------------------------------------------- /docs/source/_static/acrylic_window.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/docs/source/_static/acrylic_window.jpg -------------------------------------------------------------------------------- /docs/source/_static/cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/docs/source/_static/cover.jpg -------------------------------------------------------------------------------- /docs/source/_static/geometry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/docs/source/_static/geometry.png -------------------------------------------------------------------------------- /docs/source/_static/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/docs/source/_static/logo.png -------------------------------------------------------------------------------- /docs/source/_static/snap_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/docs/source/_static/snap_layout.png -------------------------------------------------------------------------------- /docs/source/_static/title_bar_margin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/docs/source/_static/title_bar_margin.png -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # For the full list of built-in configuration values, see the documentation: 4 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 5 | 6 | # -- Project information ----------------------------------------------------- 7 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information 8 | 9 | project = 'PyQt-Frameless-Window' 10 | copyright = '2021, zhiyiYo' 11 | author = 'zhiyiYo' 12 | release = 'v0.2.1' 13 | 14 | # -- General configuration --------------------------------------------------- 15 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration 16 | 17 | source_parsers = { 18 | '.md': 'recommonmark.parser.CommonMarkParser', 19 | } 20 | source_suffix = ['.rst', '.md'] 21 | extensions = ['recommonmark', 'sphinx_markdown_tables'] 22 | 23 | templates_path = ['_templates'] 24 | exclude_patterns = [] 25 | 26 | 27 | 28 | # -- Options for HTML output ------------------------------------------------- 29 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output 30 | 31 | html_theme = 'sphinx_rtd_theme' 32 | html_static_path = ['_static'] 33 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. PyQt-Frameless-Window documentation master file, created by 2 | sphinx-quickstart on Sat Feb 18 21:31:08 2023. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | .. raw:: html 7 | 8 |

9 | logo 10 |

11 | 12 |

13 | PyQt-Frameless-Window 14 |

15 | 16 |
17 | 18 |

19 | A cross-platform frameless window based on PyQt5 20 |

21 | 22 |

23 | 24 | Platform Win32 | Linux | macOS 25 | 26 | 27 | 28 | Download 29 | 30 | 31 | 32 | GPLv3 33 | 34 |

35 | 36 |

37 | cover 38 |

39 | 40 | 41 | Welcome to PyQt-Frameless-Window's document! 42 | ================================================= 43 | 44 | .. toctree:: 45 | :maxdepth: 2 46 | :caption: Contents 47 | 48 | quick-start 49 | usage 50 | window-effect 51 | snap-layout 52 | see-also 53 | 54 | -------------------------------------------------------------------------------- /docs/source/quick-start.md: -------------------------------------------------------------------------------- 1 | ## Quick start 2 | 3 | ### Install 4 | For PyQt5: 5 | ```shell 6 | pip install PyQt5-Frameless-Window 7 | ``` 8 | For PyQt6: 9 | ```shell 10 | pip install PyQt6-Frameless-Window 11 | ``` 12 | For PySide2: 13 | ```shell 14 | pip install PySide2-Frameless-Window 15 | ``` 16 | For PySide6: 17 | ```shell 18 | pip install PySideSix-Frameless-Window 19 | ``` 20 | 21 | 22 | ### Requirements 23 | 24 | | Platform | Requirement | 25 | | :------: | :---------: | 26 | | Win32 | pywin32 | 27 | | Linux | xcffib | 28 | | MacOS | pyobjc | -------------------------------------------------------------------------------- /docs/source/see-also.md: -------------------------------------------------------------------------------- 1 | ## See also 2 | Here are some projects that use PyQt-Frameless-Window: 3 | * [**zhiyiYo/Groove**: A cross-platform music player based on PyQt5](https://github.com/zhiyiYo/Groove) 4 | ![](./_static/Groove.jpg) 5 | 6 |
7 | 8 | * [**zhiyiYo/Alpha-Gobang-Zero**: A gobang robot based on reinforcement learning](https://github.com/zhiyiYo/Alpha-Gobang-Zero) 9 | ![](./_static/Alpha-Gobang-Zero.jpg) 10 | 11 |
12 | 13 | * [**zhiyiYo/QFluentWidgets**: A fluent design widgets library based on PyQt5](https://qfluentwidgets.com) 14 | ![](./_static/PyQt-Fluent-Widgets.jpg) -------------------------------------------------------------------------------- /docs/source/snap-layout.md: -------------------------------------------------------------------------------- 1 | ## Snap layout 2 | 3 | ### Description 4 | Snap layouts are a new Windows 11 feature to help introduce users to the power of window snapping. Snap layouts are easily accessible by hovering the mouse over a window's maximize button or pressing Win + Z. After invoking the menu that shows the available layouts, users can click on a zone in a layout to snap a window to that particular zone and then use Snap Assist to finish building an entire layout of windows. 5 | ![](./_static/snap_layout.png) 6 | 7 | ### Implementation 8 | PyQt-Frameless-Window does not enable the snap layout feature by default, because user may change the maximize button in the title bar. Here is an example shows how to enable snap layout when using the default title bar. You should replace `WindowsFramelessWindow.nativeEvent()` in `qframelesswindow/windows/__init__.py` with the following code: 9 | ```python 10 | from ..titlebar.title_bar_buttons import TitleBarButtonState 11 | 12 | def nativeEvent(self, eventType, message): 13 | """ Handle the Windows message """ 14 | msg = MSG.from_address(message.__int__()) 15 | if not msg.hWnd: 16 | return super().nativeEvent(eventType, message) 17 | 18 | if msg.message == win32con.WM_NCHITTEST and self._isResizeEnabled: 19 | pos = QCursor.pos() 20 | xPos = pos.x() - self.x() 21 | yPos = pos.y() - self.y() 22 | w, h = self.width(), self.height() 23 | lx = xPos < self.BORDER_WIDTH 24 | rx = xPos > w - self.BORDER_WIDTH 25 | ty = yPos < self.BORDER_WIDTH 26 | by = yPos > h - self.BORDER_WIDTH 27 | if lx and ty: 28 | return True, win32con.HTTOPLEFT 29 | elif rx and by: 30 | return True, win32con.HTBOTTOMRIGHT 31 | elif rx and ty: 32 | return True, win32con.HTTOPRIGHT 33 | elif lx and by: 34 | return True, win32con.HTBOTTOMLEFT 35 | elif ty: 36 | return True, win32con.HTTOP 37 | elif by: 38 | return True, win32con.HTBOTTOM 39 | elif lx: 40 | return True, win32con.HTLEFT 41 | elif rx: 42 | return True, win32con.HTRIGHT 43 | 44 | #--------------------------------------- ADDED CODE --------------------------------------# 45 | elif self.titleBar.childAt(pos-self.geometry().topLeft()) is self.titleBar.maxBtn: 46 | self.titleBar.maxBtn.setState(TitleBarButtonState.HOVER) 47 | return True, win32con.HTMAXBUTTON 48 | elif msg.message in [0x2A2, win32con.WM_MOUSELEAVE]: 49 | self.titleBar.maxBtn.setState(TitleBarButtonState.NORMAL) 50 | elif msg.message in [win32con.WM_NCLBUTTONDOWN, win32con.WM_NCLBUTTONDBLCLK]: 51 | if self.titleBar.childAt(QCursor.pos()-self.geometry().topLeft()) is self.titleBar.maxBtn: 52 | QApplication.sendEvent(self.titleBar.maxBtn, QMouseEvent( 53 | QEvent.MouseButtonPress, QPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)) 54 | return True, 0 55 | elif msg.message in [win32con.WM_NCLBUTTONUP, win32con.WM_NCRBUTTONUP]: 56 | if self.titleBar.childAt(QCursor.pos()-self.geometry().topLeft()) is self.titleBar.maxBtn: 57 | QApplication.sendEvent(self.titleBar.maxBtn, QMouseEvent( 58 | QEvent.MouseButtonRelease, QPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)) 59 | #------------------------------------------------------------------------------------------# 60 | 61 | elif msg.message == win32con.WM_NCCALCSIZE: 62 | if msg.wParam: 63 | rect = cast(msg.lParam, LPNCCALCSIZE_PARAMS).contents.rgrc[0] 64 | else: 65 | rect = cast(msg.lParam, LPRECT).contents 66 | 67 | isMax = win_utils.isMaximized(msg.hWnd) 68 | isFull = win_utils.isFullScreen(msg.hWnd) 69 | 70 | # adjust the size of client rect 71 | if isMax and not isFull: 72 | thickness = win_utils.getResizeBorderThickness(msg.hWnd) 73 | rect.top += thickness 74 | rect.left += thickness 75 | rect.right -= thickness 76 | rect.bottom -= thickness 77 | 78 | # handle the situation that an auto-hide taskbar is enabled 79 | if (isMax or isFull) and Taskbar.isAutoHide(): 80 | position = Taskbar.getPosition(msg.hWnd) 81 | if position == Taskbar.LEFT: 82 | rect.top += Taskbar.AUTO_HIDE_THICKNESS 83 | elif position == Taskbar.BOTTOM: 84 | rect.bottom -= Taskbar.AUTO_HIDE_THICKNESS 85 | elif position == Taskbar.LEFT: 86 | rect.left += Taskbar.AUTO_HIDE_THICKNESS 87 | elif position == Taskbar.RIGHT: 88 | rect.right -= Taskbar.AUTO_HIDE_THICKNESS 89 | 90 | result = 0 if not msg.wParam else win32con.WVR_REDRAW 91 | return True, result 92 | 93 | return super().nativeEvent(eventType, message) 94 | ``` 95 | 96 | We use `self.titleBar.childAt(pos-self.geometry().topLeft())` rather than `self.titleBar.childAt(xPos, yPos)`, because the size of frameless window will be larger than the screen when the window is maximized. 97 | ![](./_static/geometry.png) 98 | 99 | You can also inherit `FramelessWindow` to rewrite the `nativeEvent` in your project: 100 | ```python 101 | import sys 102 | 103 | if sys.platform != "win32": 104 | from qframelesswindow import FramelessWindow 105 | else: 106 | from ctypes.wintypes import MSG 107 | 108 | import win32con 109 | from PyQt5.QtCore import QPoint, QEvent, Qt 110 | from PyQt5.QtGui import QCursor, QMouseEvent 111 | from PyQt5.QtWidgets import QApplication 112 | 113 | from qframelesswindow import FramelessWindow as Window 114 | from qframelesswindow.titlebar.title_bar_buttons import TitleBarButtonState 115 | 116 | 117 | class FramelessWindow(Window): 118 | """ Frameless window """ 119 | 120 | def nativeEvent(self, eventType, message): 121 | """ Handle the Windows message """ 122 | msg = MSG.from_address(message.__int__()) 123 | if not msg.hWnd: 124 | return super().nativeEvent(eventType, message) 125 | 126 | if msg.message == win32con.WM_NCHITTEST and self._isResizeEnabled: 127 | if self._isHoverMaxBtn(): 128 | self.titleBar.maxBtn.setState(TitleBarButtonState.HOVER) 129 | return True, win32con.HTMAXBUTTON 130 | 131 | elif msg.message in [0x2A2, win32con.WM_MOUSELEAVE]: 132 | self.titleBar.maxBtn.setState(TitleBarButtonState.NORMAL) 133 | elif msg.message in [win32con.WM_NCLBUTTONDOWN, win32con.WM_NCLBUTTONDBLCLK] and self._isHoverMaxBtn(): 134 | e = QMouseEvent(QEvent.MouseButtonPress, QPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) 135 | QApplication.sendEvent(self.titleBar.maxBtn, e) 136 | return True, 0 137 | elif msg.message in [win32con.WM_NCLBUTTONUP, win32con.WM_NCRBUTTONUP] and self._isHoverMaxBtn(): 138 | e = QMouseEvent(QEvent.MouseButtonRelease, QPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) 139 | QApplication.sendEvent(self.titleBar.maxBtn, e) 140 | 141 | return super().nativeEvent(eventType, message) 142 | 143 | def _isHoverMaxBtn(self): 144 | pos = QCursor.pos() - self.geometry().topLeft() - self.titleBar.pos() 145 | return self.titleBar.childAt(pos) is self.titleBar.maxBtn 146 | ``` -------------------------------------------------------------------------------- /docs/source/usage.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ### Minimal example 4 | To use the frameless window, we only need to inherit `FramelessWindow` or `FramelessMainWindow`. Here is a minimal example: 5 | ```python 6 | import sys 7 | 8 | from PyQt5.QtWidgets import QApplication 9 | from qframelesswindow import FramelessWindow 10 | 11 | 12 | class Window(FramelessWindow): 13 | 14 | def __init__(self, parent=None): 15 | super().__init__(parent=parent) 16 | self.setWindowTitle("PyQt-Frameless-Window") 17 | self.titleBar.raise_() 18 | 19 | 20 | if __name__ == '__main__': 21 | app = QApplication(sys.argv) 22 | demo = Window() 23 | demo.show() 24 | sys.exit(app.exec_()) 25 | ``` 26 | For more complex requirements, see [demo.py](https://github.com/zhiyiYo/PyQt-Frameless-Window/blob/master/examples/demo.py) and [main_window.py](https://github.com/zhiyiYo/PyQt-Frameless-Window/blob/master/examples/main_window.py). 27 | 28 | ### Customize title bar 29 | PyQt-Frameless-Window uses `TitleBar` as the default title bar. `TitleBar` provides the ability to moving window and contains three basic buttons, including minimize button, maximize/restore button and close button. These buttons are inherited from `TitleBarButton`, and we can use `setXXXColor()` or qss to change the style of buttons. Here is an example: 30 | ```python 31 | from qframelesswindow import FramelessWindow, TitleBar 32 | 33 | 34 | class CustomTitleBar(TitleBar): 35 | """ Custom title bar """ 36 | 37 | def __init__(self, parent): 38 | super().__init__(parent) 39 | 40 | # customize the style of title bar button 41 | self.minBtn.setHoverColor(Qt.white) 42 | self.minBtn.setHoverBackgroundColor(QColor(0, 100, 182)) 43 | self.minBtn.setPressedColor(Qt.white) 44 | self.minBtn.setPressedBackgroundColor(QColor(54, 57, 65)) 45 | 46 | # use qss to customize title bar button 47 | self.maxBtn.setStyleSheet(""" 48 | TitleBarButton { 49 | qproperty-normalColor: black; 50 | qproperty-normalBackgroundColor: transparent; 51 | qproperty-hoverColor: white; 52 | qproperty-hoverBackgroundColor: rgb(0, 100, 182); 53 | qproperty-pressedColor: white; 54 | qproperty-pressedBackgroundColor: rgb(54, 57, 65); 55 | } 56 | """) 57 | 58 | 59 | class Window(FramelessWindow): 60 | 61 | def __init__(self, parent=None): 62 | super().__init__(parent=parent) 63 | # change the default title 64 | self.setTitleBar(CustomTitleBar(self)) 65 | ``` 66 | 67 | If we want a title bar with icon and title, just replace `TitleBar` with `StandardTitleBar`. 68 | ```python 69 | from qframelesswindow import FramelessWindow, StandardTitleBar 70 | 71 | 72 | class Window(FramelessWindow): 73 | 74 | def __init__(self, parent=None): 75 | super().__init__(parent=parent) 76 | # replace the default title bar with StandardTitleBar 77 | self.setTitleBar(StandardTitleBar(self)) 78 | 79 | self.setWindowIcon(QIcon("screenshot/logo.png")) 80 | self.setWindowTitle("PyQt-Frameless-Window") 81 | 82 | # don't forget to put the title bar at the top 83 | self.titleBar.raise_() 84 | ``` 85 | 86 | When the window icon or title changes, the icon and title of `StandardTitleBar` will also change accordingly. However, we can also use `StandardTitleBar.setTitle()` or `StandardTitleBar.setIcon()` to change them manually. 87 | 88 | ### Work with Qt Designer 89 | To prevent the title bar from being blocked by other widgets, we need to leave **32px** space for title bar. 90 | ![](_static/title_bar_margin.png) 91 | 92 | After compiling the ui file into a Ui class, we can use the frameless window through multiple inheritance. Here is an example: 93 | ```python 94 | class Ui_Form(object): 95 | def setupUi(self, Form): 96 | Form.resize(400, 423) 97 | self.verticalLayout_2 = QVBoxLayout(Form) 98 | self.verticalLayout_2.setContentsMargins(-1, 32, -1, -1) 99 | self.frame_2 = QFrame(Form) 100 | self.verticalLayout = QVBoxLayout(self.frame_2) 101 | self.horizontalLayout = QHBoxLayout() 102 | self.pushButton = QPushButton(self.frame_2) 103 | self.horizontalLayout.addWidget(self.pushButton) 104 | self.lineEdit = QLineEdit(self.frame_2) 105 | self.horizontalLayout.addWidget(self.lineEdit) 106 | self.verticalLayout.addLayout(self.horizontalLayout) 107 | self.horizontalLayout_2 = QHBoxLayout() 108 | self.pushButton_2 = QPushButton(self.frame_2) 109 | self.horizontalLayout_2.addWidget(self.pushButton_2) 110 | self.lineEdit_2 = QLineEdit(self.frame_2) 111 | self.horizontalLayout_2.addWidget(self.lineEdit_2) 112 | self.verticalLayout.addLayout(self.horizontalLayout_2) 113 | self.verticalLayout_2.addWidget(self.frame_2) 114 | self.frame = QFrame(Form) 115 | self.horizontalLayout_3 = QHBoxLayout(self.frame) 116 | self.tableView = QTableView(self.frame) 117 | self.horizontalLayout_3.addWidget(self.tableView) 118 | self.verticalLayout_2.addWidget(self.frame) 119 | 120 | self.retranslateUi(Form) 121 | 122 | def retranslateUi(self, Form): 123 | _translate = QCoreApplication.translate 124 | Form.setWindowTitle(_translate("Form", "Form")) 125 | self.pushButton.setText(_translate("Form", "选择文件")) 126 | self.pushButton_2.setText(_translate("Form", "创建路径")) 127 | 128 | 129 | class Window(FramelessWindow, Ui_Form): 130 | 131 | def __init__(self, parent=None): 132 | super().__init__(parent) 133 | self.setupUi(self) 134 | ``` -------------------------------------------------------------------------------- /docs/source/window-effect.md: -------------------------------------------------------------------------------- 1 | ## Window effect 2 | PyQt-Frameless-Window use `WindowEffect` class to control the effect of frameless window. You can add shadow, animation or blur effect to window through `WindowEffect`. 3 | 4 | ### Acrylic effect 5 | PyQt-Frameless-Window provides the `AcrylicWindow` class, which uses the acrylic blur effect. 6 | ![](_static/acrylic_window.jpg) 7 | 8 | Here is an minimal example: 9 | ```python 10 | from qframelesswindow import AcrylicWindow 11 | 12 | 13 | class Window(AcrylicWindow): 14 | 15 | def __init__(self, parent=None): 16 | super().__init__(parent=parent) 17 | self.setWindowTitle("Acrylic Window") 18 | self.titleBar.raise_() 19 | 20 | # customize acrylic effect 21 | # self.windowEffect.setAcrylicEffect(self.winId(), "106EBE99") 22 | 23 | # you can also enable mica effect on Win11 24 | # self.windowEffect.setMicaEffect(self.winId(), False) 25 | ``` 26 | 27 | Because moving or resizing the acrylic window on Win10 may get stuck, we can use the following method to toggle acrylic effect: 28 | ```python 29 | def setAcrylicEffectEnabled(self, enable: bool): 30 | """ set acrylic effect enabled """ 31 | self.setStyleSheet(f"background:{'transparent' if enable else '#F2F2F2'}") 32 | if enable: 33 | self.windowEffect.setAcrylicEffect(self.winId(), "F2F2F299") 34 | if QOperatingSystemVersion.current() != QOperatingSystemVersion.Windows10: 35 | self.windowEffect.addShadowEffect(self.winId()) 36 | else: 37 | self.windowEffect.addShadowEffect(self.winId()) 38 | self.windowEffect.removeBackgroundEffect(self.winId()) 39 | ``` -------------------------------------------------------------------------------- /examples/acrylic_demo.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | 4 | from PyQt5.QtCore import Qt 5 | from PyQt5.QtWidgets import QApplication 6 | from qframelesswindow import AcrylicWindow 7 | 8 | 9 | class Window(AcrylicWindow): 10 | 11 | def __init__(self, parent=None): 12 | super().__init__(parent=parent) 13 | self.setWindowTitle("Acrylic Window") 14 | self.titleBar.raise_() 15 | 16 | # customize acrylic effect 17 | # self.windowEffect.setAcrylicEffect(self.winId(), "106EBE99") 18 | 19 | # you can also enable mica effect on Win11 20 | # self.windowEffect.setMicaEffect(self.winId(), isDarkMode=False, isAlt=False) 21 | 22 | 23 | if __name__ == '__main__': 24 | # enable dpi scale 25 | QApplication.setHighDpiScaleFactorRoundingPolicy( 26 | Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) 27 | QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) 28 | QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) 29 | 30 | app = QApplication(sys.argv) 31 | demo = Window() 32 | demo.show() 33 | sys.exit(app.exec_()) 34 | -------------------------------------------------------------------------------- /examples/demo.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | 4 | from PyQt5.QtCore import QRect, QSize, Qt 5 | from PyQt5.QtGui import QColor, QPixmap, QIcon 6 | from PyQt5.QtWidgets import QApplication, QLabel 7 | 8 | from qframelesswindow import FramelessWindow, StandardTitleBar 9 | 10 | 11 | class CustomTitleBar(StandardTitleBar): 12 | """ Custom title bar """ 13 | 14 | def __init__(self, parent): 15 | super().__init__(parent) 16 | 17 | # customize the style of title bar button 18 | self.minBtn.setHoverColor(Qt.white) 19 | self.minBtn.setHoverBackgroundColor(QColor(0, 100, 182)) 20 | self.minBtn.setPressedColor(Qt.white) 21 | self.minBtn.setPressedBackgroundColor(QColor(54, 57, 65)) 22 | 23 | # use qss to customize title bar button 24 | self.maxBtn.setStyleSheet(""" 25 | TitleBarButton { 26 | qproperty-hoverColor: white; 27 | qproperty-hoverBackgroundColor: rgb(0, 100, 182); 28 | qproperty-pressedColor: white; 29 | qproperty-pressedBackgroundColor: rgb(54, 57, 65); 30 | } 31 | """) 32 | 33 | 34 | class Window(FramelessWindow): 35 | 36 | def __init__(self, parent=None): 37 | super().__init__(parent=parent) 38 | # change the default title bar if you like 39 | self.setTitleBar(CustomTitleBar(self)) 40 | 41 | self.label = QLabel(self) 42 | self.label.setScaledContents(True) 43 | self.label.setPixmap(QPixmap("screenshot/shoko.png")) 44 | 45 | self.setWindowIcon(QIcon("screenshot/logo.png")) 46 | self.setWindowTitle("PyQt-Frameless-Window") 47 | self.setStyleSheet("background:white") 48 | 49 | self.titleBar.raise_() 50 | 51 | # customize the area of system title bar button, only works for macOS 52 | if sys.platform == "darwin": 53 | self.setSystemTitleBarButtonVisible(True) 54 | self.titleBar.minBtn.hide() 55 | self.titleBar.maxBtn.hide() 56 | self.titleBar.closeBtn.hide() 57 | 58 | def resizeEvent(self, e): 59 | # don't forget to call the resizeEvent() of super class 60 | super().resizeEvent(e) 61 | length = min(self.width(), self.height()) 62 | self.label.resize(length, length) 63 | self.label.move( 64 | self.width() // 2 - length // 2, 65 | self.height() // 2 - length // 2 66 | ) 67 | 68 | def systemTitleBarRect(self, size: QSize) -> QRect: 69 | """ Returns the system title bar rect, only works for macOS 70 | 71 | Parameters 72 | ---------- 73 | size: QSize 74 | original system title bar rect 75 | """ 76 | return QRect(size.width() - 75, 0, 75, size.height()) 77 | 78 | 79 | if __name__ == "__main__": 80 | # enable dpi scale 81 | QApplication.setHighDpiScaleFactorRoundingPolicy( 82 | Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) 83 | QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) 84 | QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) 85 | 86 | # run app 87 | app = QApplication(sys.argv) 88 | demo = Window() 89 | demo.show() 90 | sys.exit(app.exec_()) 91 | -------------------------------------------------------------------------------- /examples/main_window.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | 4 | from PyQt5.QtCore import Qt 5 | from PyQt5.QtWidgets import QApplication, QLabel, QMenuBar, QMenu, QStatusBar, QTextEdit, QHBoxLayout 6 | 7 | from qframelesswindow import FramelessMainWindow, FramelessDialog 8 | 9 | 10 | class MainWindow(FramelessMainWindow): 11 | 12 | def __init__(self): 13 | super().__init__() 14 | self.setWindowTitle("Frameless Main Window") 15 | 16 | # add menu bar 17 | menuBar = QMenuBar(self.titleBar) 18 | menu = QMenu('File(&F)', self) 19 | menu.addAction('open') 20 | menu.addAction('save') 21 | menuBar.addMenu(menu) 22 | menuBar.addAction('Edit(&E)') 23 | menuBar.addAction('Select(&S)') 24 | menuBar.addAction('Help(&H)', self.showHelpDialog) 25 | self.titleBar.layout().insertWidget(0, menuBar, 0, Qt.AlignLeft) 26 | self.titleBar.layout().insertStretch(1, 1) 27 | self.setMenuWidget(self.titleBar) 28 | 29 | # add status bar 30 | statusBar = QStatusBar(self) 31 | statusBar.addWidget(QLabel('row 1')) 32 | statusBar.addWidget(QLabel('column 1')) 33 | self.setStatusBar(statusBar) 34 | 35 | # set central widget 36 | self.textEdit = QTextEdit() 37 | self.setCentralWidget(self.textEdit) 38 | 39 | self.setStyleSheet(""" 40 | QMenuBar{background: #F0F0F0; padding: 5px 0} 41 | QTextEdit{border: none; font-size: 15px} 42 | QDialog > QLabel{font-size: 15px} 43 | """) 44 | 45 | def showHelpDialog(self): 46 | w = FramelessDialog(self) 47 | 48 | # add a label to dialog 49 | w.setLayout(QHBoxLayout()) 50 | w.layout().addWidget(QLabel('Frameless Dialog'), 0, Qt.AlignCenter) 51 | 52 | # raise title bar 53 | w.titleBar.raise_() 54 | w.resize(300, 300) 55 | 56 | # disable resizing dialog 57 | w.setResizeEnabled(False) 58 | w.exec() 59 | 60 | 61 | if __name__ == '__main__': 62 | # enable dpi scale 63 | QApplication.setHighDpiScaleFactorRoundingPolicy( 64 | Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) 65 | QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) 66 | QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) 67 | 68 | app = QApplication(sys.argv) 69 | 70 | # fix issue #50 71 | app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings) 72 | 73 | window = MainWindow() 74 | window.show() 75 | app.exec() 76 | -------------------------------------------------------------------------------- /examples/screen_capture_filter.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | 4 | from PyQt5.QtCore import Qt 5 | from PyQt5.QtWidgets import QApplication 6 | 7 | from qframelesswindow import FramelessWindow 8 | from qframelesswindow.utils import ScreenCaptureFilter 9 | 10 | 11 | 12 | class Window(FramelessWindow): 13 | 14 | def __init__(self, parent=None): 15 | super().__init__(parent=parent) 16 | self.setWindowTitle("PyQt-Frameless-Window") 17 | 18 | # disable screen capture 19 | self.installEventFilter(ScreenCaptureFilter(self)) 20 | 21 | 22 | 23 | if __name__ == "__main__": 24 | # enable dpi scale 25 | QApplication.setHighDpiScaleFactorRoundingPolicy( 26 | Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) 27 | QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) 28 | QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) 29 | 30 | # run app 31 | app = QApplication(sys.argv) 32 | demo = Window() 33 | demo.show() 34 | sys.exit(app.exec_()) 35 | -------------------------------------------------------------------------------- /examples/web_engine.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | 4 | from PyQt5.QtCore import QUrl, Qt 5 | from PyQt5.QtWidgets import QApplication, QHBoxLayout 6 | 7 | from qframelesswindow import FramelessWindow, TitleBar, StandardTitleBar 8 | from qframelesswindow.webengine import FramelessWebEngineView 9 | 10 | 11 | class Window(FramelessWindow): 12 | 13 | def __init__(self, parent=None): 14 | super().__init__(parent=parent) 15 | # change the default title bar if you like 16 | self.setTitleBar(StandardTitleBar(self)) 17 | 18 | self.hBoxLayout = QHBoxLayout(self) 19 | 20 | # must replace QWebEngineView with FramelessWebEngineView 21 | self.webEngine = FramelessWebEngineView(self) 22 | 23 | self.hBoxLayout.setContentsMargins(0, self.titleBar.height(), 0, 0) 24 | self.hBoxLayout.addWidget(self.webEngine) 25 | 26 | # load web page 27 | self.webEngine.load(QUrl("https://qfluentwidgets.com/")) 28 | self.resize(1200, 800) 29 | 30 | self.titleBar.raise_() 31 | 32 | 33 | 34 | if __name__ == "__main__": 35 | # enable dpi scale 36 | QApplication.setHighDpiScaleFactorRoundingPolicy( 37 | Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) 38 | QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) 39 | QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) 40 | 41 | app = QApplication(sys.argv) 42 | demo = Window() 43 | demo.show() 44 | app.exec() 45 | -------------------------------------------------------------------------------- /qframelesswindow/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | PyQt5-Frameless-Window 3 | ====================== 4 | A cross-platform frameless window based on pyqt5, support Win32, Linux and macOS. 5 | 6 | Documentation is available in the docstrings and 7 | online at https://pyqt-frameless-window.readthedocs.io. 8 | 9 | Examples are available at https://github.com/zhiyiYo/PyQt-Frameless-Window/tree/master/examples. 10 | 11 | :copyright: (c) 2021 by zhiyiYo. 12 | :license: GPLv3, see LICENSE for more details. 13 | """ 14 | 15 | __version__ = "0.7.3" 16 | __author__ = "zhiyiYo" 17 | 18 | import sys 19 | 20 | from PyQt5.QtCore import QTimer 21 | from PyQt5.QtWidgets import QDialog, QMainWindow 22 | 23 | from .titlebar import TitleBar, TitleBarButton, SvgTitleBarButton, StandardTitleBar, TitleBarBase 24 | 25 | if sys.platform == "win32": 26 | from .windows import AcrylicWindow 27 | from .windows import WindowsFramelessWindow as FramelessWindow 28 | from .windows import WindowsWindowEffect as WindowEffect 29 | elif sys.platform == "darwin": 30 | from .mac import AcrylicWindow 31 | from .mac import MacFramelessWindow as FramelessWindow 32 | from .mac import MacWindowEffect as WindowEffect 33 | else: 34 | from .linux import LinuxFramelessWindow as FramelessWindow 35 | from .linux import LinuxWindowEffect as WindowEffect 36 | 37 | AcrylicWindow = FramelessWindow 38 | 39 | 40 | class FramelessDialog(QDialog, FramelessWindow): 41 | """ Frameless dialog """ 42 | 43 | def __init__(self, parent=None): 44 | super().__init__(parent) 45 | self.titleBar.minBtn.hide() 46 | self.titleBar.maxBtn.hide() 47 | self.titleBar.setDoubleClickEnabled(False) 48 | self.windowEffect.disableMaximizeButton(self.winId()) 49 | 50 | 51 | class FramelessMainWindow(QMainWindow, FramelessWindow): 52 | """ Frameless main window """ 53 | 54 | def __init__(self, parent=None): 55 | super().__init__(parent) -------------------------------------------------------------------------------- /qframelesswindow/_rc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/qframelesswindow/_rc/__init__.py -------------------------------------------------------------------------------- /qframelesswindow/_rc/resource.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Resource object code 4 | # 5 | # Created by: The Resource Compiler for PyQt5 (Qt v5.15.2) 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | from PyQt5 import QtCore 10 | 11 | qt_resource_data = b"\ 12 | \x00\x00\x01\x0e\ 13 | \x3c\ 14 | \x73\x76\x67\x20\x77\x69\x64\x74\x68\x3d\x22\x34\x35\x70\x74\x22\ 15 | \x20\x68\x65\x69\x67\x68\x74\x3d\x22\x33\x30\x70\x74\x22\x20\x76\ 16 | \x65\x72\x73\x69\x6f\x6e\x3d\x22\x31\x2e\x31\x22\x20\x76\x69\x65\ 17 | \x77\x42\x6f\x78\x3d\x22\x30\x20\x30\x20\x31\x35\x2e\x38\x37\x35\ 18 | \x20\x31\x30\x2e\x35\x38\x33\x22\x20\x78\x6d\x6c\x6e\x73\x3d\x22\ 19 | \x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x77\x33\x2e\x6f\x72\ 20 | \x67\x2f\x32\x30\x30\x30\x2f\x73\x76\x67\x22\x3e\x0d\x0a\x20\x3c\ 21 | \x67\x20\x66\x69\x6c\x6c\x3d\x22\x6e\x6f\x6e\x65\x22\x20\x73\x74\ 22 | \x72\x6f\x6b\x65\x3d\x22\x23\x30\x30\x30\x22\x20\x73\x74\x72\x6f\ 23 | \x6b\x65\x2d\x77\x69\x64\x74\x68\x3d\x22\x2e\x31\x37\x36\x33\x39\ 24 | \x22\x3e\x0d\x0a\x20\x20\x3c\x70\x61\x74\x68\x20\x64\x3d\x22\x6d\ 25 | \x36\x2e\x31\x32\x39\x35\x20\x33\x2e\x36\x36\x30\x31\x20\x33\x2e\ 26 | \x32\x36\x33\x32\x20\x33\x2e\x32\x36\x33\x32\x7a\x22\x2f\x3e\x0d\ 27 | \x0a\x20\x20\x3c\x70\x61\x74\x68\x20\x64\x3d\x22\x6d\x39\x2e\x33\ 28 | \x39\x32\x37\x20\x33\x2e\x36\x36\x30\x31\x2d\x33\x2e\x32\x36\x33\ 29 | \x32\x20\x33\x2e\x32\x36\x33\x32\x7a\x22\x2f\x3e\x0d\x0a\x20\x3c\ 30 | \x2f\x67\x3e\x0d\x0a\x3c\x2f\x73\x76\x67\x3e\x0d\x0a\ 31 | " 32 | 33 | qt_resource_name = b"\ 34 | \x00\x10\ 35 | \x0a\xb5\xe4\x07\ 36 | \x00\x71\ 37 | \x00\x66\x00\x72\x00\x61\x00\x6d\x00\x65\x00\x6c\x00\x65\x00\x73\x00\x73\x00\x77\x00\x69\x00\x6e\x00\x64\x00\x6f\x00\x77\ 38 | \x00\x09\ 39 | \x06\x98\x8e\xa7\ 40 | \x00\x63\ 41 | \x00\x6c\x00\x6f\x00\x73\x00\x65\x00\x2e\x00\x73\x00\x76\x00\x67\ 42 | " 43 | 44 | qt_resource_struct_v1 = b"\ 45 | \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\ 46 | \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\ 47 | \x00\x00\x00\x26\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\ 48 | " 49 | 50 | qt_resource_struct_v2 = b"\ 51 | \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\ 52 | \x00\x00\x00\x00\x00\x00\x00\x00\ 53 | \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x02\ 54 | \x00\x00\x00\x00\x00\x00\x00\x00\ 55 | \x00\x00\x00\x26\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\ 56 | \x00\x00\x01\x85\x86\x8c\x35\x15\ 57 | " 58 | 59 | qt_version = [int(v) for v in QtCore.qVersion().split('.')] 60 | if qt_version < [5, 8, 0]: 61 | rcc_version = 1 62 | qt_resource_struct = qt_resource_struct_v1 63 | else: 64 | rcc_version = 2 65 | qt_resource_struct = qt_resource_struct_v2 66 | 67 | def qInitResources(): 68 | QtCore.qRegisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data) 69 | 70 | def qCleanupResources(): 71 | QtCore.qUnregisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data) 72 | 73 | qInitResources() 74 | -------------------------------------------------------------------------------- /qframelesswindow/_rc/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | title_bar/close.svg 4 | 5 | -------------------------------------------------------------------------------- /qframelesswindow/_rc/title_bar/close.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /qframelesswindow/linux/__init__.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | from PyQt5.QtCore import QCoreApplication, QEvent, Qt, QSize, QRect 3 | from PyQt5.QtGui import QMouseEvent 4 | from PyQt5.QtWidgets import QWidget 5 | 6 | from ..titlebar import TitleBar 7 | from ..utils.linux_utils import LinuxMoveResize 8 | from .window_effect import LinuxWindowEffect 9 | 10 | 11 | class LinuxFramelessWindow(QWidget): 12 | """ Frameless window for Linux system """ 13 | 14 | BORDER_WIDTH = 5 15 | 16 | def __init__(self, parent=None): 17 | super().__init__(parent=parent) 18 | self.windowEffect = LinuxWindowEffect(self) 19 | self.titleBar = TitleBar(self) 20 | self._isSystemButtonVisible = False 21 | self._isResizeEnabled = True 22 | 23 | self.updateFrameless() 24 | QCoreApplication.instance().installEventFilter(self) 25 | 26 | self.titleBar.raise_() 27 | self.resize(500, 500) 28 | 29 | def resizeEvent(self, e): 30 | super().resizeEvent(e) 31 | self.titleBar.resize(self.width(), self.titleBar.height()) 32 | 33 | def updateFrameless(self): 34 | self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint) 35 | 36 | def setStayOnTop(self, isTop: bool): 37 | """ set the stay on top status """ 38 | if isTop: 39 | self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint) 40 | else: 41 | self.setWindowFlags(self.windowFlags() & ~Qt.WindowStaysOnTopHint) 42 | 43 | self.updateFrameless() 44 | self.show() 45 | 46 | def toggleStayOnTop(self): 47 | """ toggle the stay on top status """ 48 | if self.windowFlags() & Qt.WindowStaysOnTopHint: 49 | self.setStayOnTop(False) 50 | else: 51 | self.setStayOnTop(True) 52 | 53 | def setTitleBar(self, titleBar): 54 | """ set custom title bar 55 | 56 | Parameters 57 | ---------- 58 | titleBar: TitleBar 59 | title bar 60 | """ 61 | self.titleBar.deleteLater() 62 | self.titleBar.hide() 63 | self.titleBar = titleBar 64 | self.titleBar.setParent(self) 65 | self.titleBar.raise_() 66 | 67 | def setResizeEnabled(self, isEnabled: bool): 68 | """ set whether resizing is enabled """ 69 | self._isResizeEnabled = isEnabled 70 | 71 | def isSystemButtonVisible(self): 72 | """ Returns whether the system title bar button is visible """ 73 | return self._isSystemButtonVisible 74 | 75 | def setSystemTitleBarButtonVisible(self, isVisible): 76 | """ set the visibility of system title bar button, only works for macOS """ 77 | pass 78 | 79 | def systemTitleBarRect(self, size: QSize) -> QRect: 80 | """ Returns the system title bar rect, only works for macOS 81 | 82 | Parameters 83 | ---------- 84 | size: QSize 85 | original system title bar rect 86 | """ 87 | return QRect(0, 0, size.width(), size.height()) 88 | 89 | def eventFilter(self, obj, event): 90 | et = event.type() 91 | if et != QEvent.MouseButtonPress and et != QEvent.MouseMove or not self._isResizeEnabled: 92 | return False 93 | 94 | edges = Qt.Edges() 95 | pos = QMouseEvent(event).globalPos() - self.pos() 96 | if pos.x() < self.BORDER_WIDTH: 97 | edges |= Qt.LeftEdge 98 | if pos.x() >= self.width()-self.BORDER_WIDTH: 99 | edges |= Qt.RightEdge 100 | if pos.y() < self.BORDER_WIDTH: 101 | edges |= Qt.TopEdge 102 | if pos.y() >= self.height()-self.BORDER_WIDTH: 103 | edges |= Qt.BottomEdge 104 | 105 | # change cursor 106 | if et == QEvent.MouseMove and self.windowState() == Qt.WindowNoState: 107 | if edges in (Qt.LeftEdge | Qt.TopEdge, Qt.RightEdge | Qt.BottomEdge): 108 | self.setCursor(Qt.SizeFDiagCursor) 109 | elif edges in (Qt.RightEdge | Qt.TopEdge, Qt.LeftEdge | Qt.BottomEdge): 110 | self.setCursor(Qt.SizeBDiagCursor) 111 | elif edges in (Qt.TopEdge, Qt.BottomEdge): 112 | self.setCursor(Qt.SizeVerCursor) 113 | elif edges in (Qt.LeftEdge, Qt.RightEdge): 114 | self.setCursor(Qt.SizeHorCursor) 115 | else: 116 | self.setCursor(Qt.ArrowCursor) 117 | 118 | elif obj in (self, self.titleBar) and et == QEvent.MouseButtonPress and edges: 119 | LinuxMoveResize.starSystemResize(self, event.globalPos(), edges) 120 | 121 | return super().eventFilter(obj, event) 122 | -------------------------------------------------------------------------------- /qframelesswindow/linux/window_effect.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | from PyQt5.QtGui import QColor 3 | 4 | 5 | class LinuxWindowEffect: 6 | """ Linux window effect """ 7 | 8 | def __init__(self, window): 9 | self.window = window 10 | 11 | def setAcrylicEffect(self, hWnd, gradientColor="F2F2F230", isEnableShadow=True, animationId=0): 12 | """ set acrylic effect for window 13 | 14 | Parameter 15 | ---------- 16 | hWnd: int or `sip.voidptr` 17 | window handle 18 | 19 | gradientColor: str 20 | hexadecimal acrylic mixed color, corresponding to RGBA components 21 | 22 | isEnableShadow: bool 23 | whether to enable window shadow 24 | 25 | animationId: int 26 | turn on blur animation or not 27 | """ 28 | pass 29 | 30 | def setBorderAccentColor(self, hWnd, color: QColor): 31 | """ Set the border color of the window 32 | 33 | Parameters 34 | ---------- 35 | hWnd: int or `sip.voidptr` 36 | Window handle 37 | 38 | color: QColor 39 | Border Accent color 40 | """ 41 | pass 42 | 43 | def removeBorderAccentColor(self, hWnd): 44 | """ Remove the border color of the window 45 | 46 | Parameters 47 | ---------- 48 | hWnd: int or `sip.voidptr` 49 | Window handle 50 | """ 51 | pass 52 | 53 | def setMicaEffect(self, hWnd, isDarkMode=False, isAlt=False): 54 | """ Add mica effect to the window (Win11 only) 55 | 56 | Parameters 57 | ---------- 58 | hWnd: int or `sip.voidptr` 59 | Window handle 60 | 61 | isDarkMode: bool 62 | whether to use dark mode mica effect 63 | 64 | isAlt: bool 65 | whether to use mica alt effect 66 | """ 67 | pass 68 | 69 | def setAeroEffect(self, hWnd): 70 | """ add Aero effect to the window 71 | 72 | Parameter 73 | ---------- 74 | hWnd: int or `sip.voidptr` 75 | Window handle 76 | """ 77 | pass 78 | 79 | def setTransparentEffect(self, hWnd): 80 | """ set transparent effect for window 81 | 82 | Parameters 83 | ---------- 84 | hWnd : int or `sip.voidptr` 85 | Window handle 86 | """ 87 | pass 88 | 89 | def removeBackgroundEffect(self, hWnd): 90 | """ Remove background effect 91 | 92 | Parameters 93 | ---------- 94 | hWnd : int or `sip.voidptr` 95 | Window handle 96 | """ 97 | pass 98 | 99 | def addShadowEffect(self, hWnd): 100 | """ add shadow to window 101 | 102 | Parameter 103 | ---------- 104 | hWnd: int or `sip.voidptr` 105 | Window handle 106 | """ 107 | pass 108 | 109 | def addMenuShadowEffect(self, hWnd): 110 | """ add shadow to menu 111 | 112 | Parameter 113 | ---------- 114 | hWnd: int or `sip.voidptr` 115 | Window handle 116 | """ 117 | pass 118 | 119 | @staticmethod 120 | def removeMenuShadowEffect(hWnd): 121 | """ Remove shadow from pop-up menu 122 | 123 | Parameters 124 | ---------- 125 | hWnd: int or `sip.voidptr` 126 | Window handle 127 | """ 128 | pass 129 | 130 | def removeShadowEffect(self, hWnd): 131 | """ Remove shadow from the window 132 | 133 | Parameters 134 | ---------- 135 | hWnd: int or `sip.voidptr` 136 | Window handle 137 | """ 138 | pass 139 | 140 | @staticmethod 141 | def addWindowAnimation(hWnd): 142 | """ Enables the maximize and minimize animation of the window 143 | 144 | Parameters 145 | ---------- 146 | hWnd : int or `sip.voidptr` 147 | Window handle 148 | """ 149 | 150 | @staticmethod 151 | def disableMaximizeButton(hWnd): 152 | """ Disable the maximize button of window 153 | 154 | Parameters 155 | ---------- 156 | hWnd : int or `sip.voidptr` 157 | Window handle 158 | """ 159 | 160 | def enableBlurBehindWindow(self, hWnd): 161 | """ enable the blur effect behind the whole client 162 | Parameters 163 | ---------- 164 | hWnd: int or `sip.voidptr` 165 | Window handle 166 | """ -------------------------------------------------------------------------------- /qframelesswindow/mac/__init__.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import Cocoa 3 | import objc 4 | from PyQt5.QtCore import QEvent, Qt, QRect, QSize, QPoint, QTimer 5 | from PyQt5.QtWidgets import QWidget 6 | 7 | from ..titlebar import TitleBar 8 | from .window_effect import MacWindowEffect 9 | 10 | 11 | class MacFramelessWindow(QWidget): 12 | """ Frameless window for Linux system """ 13 | 14 | def __init__(self, parent=None): 15 | super().__init__(parent=parent) 16 | self.windowEffect = MacWindowEffect(self) 17 | # must enable acrylic effect before creating title bar 18 | if isinstance(self, AcrylicWindow): 19 | self.windowEffect.setAcrylicEffect(self.winId()) 20 | 21 | self.titleBar = TitleBar(self) 22 | self._isSystemButtonVisible = False 23 | self._isResizeEnabled = True 24 | 25 | self.updateFrameless() 26 | 27 | self.resize(500, 500) 28 | self.titleBar.raise_() 29 | 30 | def updateFrameless(self): 31 | """ update frameless window """ 32 | view = objc.objc_object(c_void_p=self.winId().__int__()) 33 | self.__nsWindow = view.window() 34 | 35 | # hide system title bar 36 | isButtonVisible = self.isSystemButtonVisible() 37 | self._hideSystemTitleBar() 38 | self.setSystemTitleBarButtonVisible(isButtonVisible) 39 | 40 | def setStayOnTop(self, isTop: bool): 41 | """ set the stay on top status """ 42 | if isTop: 43 | self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint) 44 | else: 45 | self.setWindowFlags(self.windowFlags() & ~Qt.WindowStaysOnTopHint) 46 | 47 | self.updateFrameless() 48 | self.show() 49 | 50 | def toggleStayOnTop(self): 51 | """ toggle the stay on top status """ 52 | if self.windowFlags() & Qt.WindowStaysOnTopHint: 53 | self.setStayOnTop(False) 54 | else: 55 | self.setStayOnTop(True) 56 | 57 | def setTitleBar(self, titleBar): 58 | """ set custom title bar 59 | 60 | Parameters 61 | ---------- 62 | titleBar: TitleBar 63 | title bar 64 | """ 65 | self.titleBar.deleteLater() 66 | self.titleBar.hide() 67 | self.titleBar = titleBar 68 | self.titleBar.setParent(self) 69 | self.titleBar.raise_() 70 | 71 | def setResizeEnabled(self, isEnabled: bool): 72 | """ set whether resizing is enabled """ 73 | self._isResizeEnabled = isEnabled 74 | 75 | def resizeEvent(self, e): 76 | super().resizeEvent(e) 77 | self.titleBar.resize(self.width(), self.titleBar.height()) 78 | 79 | def paintEvent(self, e): 80 | super().paintEvent(e) 81 | self._hideSystemTitleBar(self.isSystemButtonVisible()) 82 | 83 | def changeEvent(self, event): 84 | if event.type() == QEvent.WindowStateChange: 85 | self._hideSystemTitleBar(self.isSystemButtonVisible()) 86 | 87 | # Delay must be added, otherwise the buttons will be misplaced 88 | QTimer.singleShot(1, self._updateSystemButtonRect) 89 | elif event.type() == QEvent.Resize: 90 | self._updateSystemButtonRect() 91 | 92 | def _hideSystemTitleBar(self, showButton=False): 93 | # extend view to title bar region 94 | self.__nsWindow.setStyleMask_( 95 | self.__nsWindow.styleMask() | Cocoa.NSFullSizeContentViewWindowMask) 96 | self.__nsWindow.setTitlebarAppearsTransparent_(True) 97 | 98 | # disable the moving behavior of system 99 | self.__nsWindow.setMovableByWindowBackground_(False) 100 | self.__nsWindow.setMovable_(False) 101 | 102 | # hide title bar buttons and title 103 | self.__nsWindow.setTitleVisibility_(Cocoa.NSWindowTitleHidden) 104 | self.setSystemTitleBarButtonVisible(showButton) 105 | 106 | def isSystemButtonVisible(self): 107 | return self._isSystemButtonVisible 108 | 109 | def setSystemTitleBarButtonVisible(self, isVisible): 110 | self._isSystemButtonVisible = isVisible 111 | self.__nsWindow.setShowsToolbarButton_(isVisible) 112 | 113 | isHidden = not isVisible 114 | self.__nsWindow.standardWindowButton_(Cocoa.NSWindowCloseButton).setHidden_(isHidden) 115 | self.__nsWindow.standardWindowButton_(Cocoa.NSWindowZoomButton).setHidden_(isHidden) 116 | self.__nsWindow.standardWindowButton_(Cocoa.NSWindowMiniaturizeButton).setHidden_(isHidden) 117 | 118 | if isVisible: 119 | self._updateSystemButtonRect() 120 | 121 | def _updateSystemButtonRect(self): 122 | if not self.isSystemButtonVisible(): 123 | return 124 | 125 | # get system title bar button 126 | leftButton = self.__nsWindow.standardWindowButton_(Cocoa.NSWindowCloseButton) 127 | midButton = self.__nsWindow.standardWindowButton_(Cocoa.NSWindowMiniaturizeButton) 128 | rightButton = self.__nsWindow.standardWindowButton_(Cocoa.NSWindowZoomButton) 129 | 130 | # get system title bar 131 | titlebar = rightButton.superview() 132 | titlebarHeight = int(titlebar.frame().size.height) 133 | 134 | spacing = midButton.frame().origin.x - leftButton.frame().origin.x 135 | width = midButton.frame().size.width 136 | height = midButton.frame().size.height 137 | 138 | if self.__nsWindow.contentView(): 139 | viewSize = self.__nsWindow.contentView().frame().size 140 | else: 141 | viewSize = self.__nsWindow.frame().size 142 | 143 | center = self.systemTitleBarRect(QSize(int(viewSize.width), titlebarHeight)).center() 144 | 145 | # The origin of the NSWindow coordinate system is in the lower left corner, we do the necessary transformations 146 | center.setY(titlebarHeight - center.y()) 147 | 148 | # adjust the position of minimize button 149 | centerOrigin = Cocoa.NSPoint(center.x() - width // 2, center.y() - height // 2) 150 | midButton.setFrameOrigin_(centerOrigin) 151 | 152 | # adjust the position of close button 153 | leftOrigin = Cocoa.NSPoint(centerOrigin.x - spacing, centerOrigin.y) 154 | leftButton.setFrameOrigin_(leftOrigin) 155 | 156 | # adjust the position of zoom button 157 | rightOrigin = Cocoa.NSPoint(centerOrigin.x + spacing, centerOrigin.y) 158 | rightButton.setFrameOrigin_(rightOrigin) 159 | 160 | def systemTitleBarRect(self, size: QSize) -> QRect: 161 | """ Returns the system title bar rect 162 | 163 | Parameters 164 | ---------- 165 | size: QSize 166 | original system title bar rect 167 | """ 168 | return QRect(0, 0, 75, size.height()) 169 | 170 | 171 | class AcrylicWindow(MacFramelessWindow): 172 | """ A frameless window with acrylic effect """ 173 | 174 | def __init__(self, parent=None): 175 | super().__init__(parent) 176 | self.setAttribute(Qt.WA_TranslucentBackground) 177 | self.windowEffect.setAcrylicEffect(self.winId()) 178 | self.setStyleSheet("background: transparent") 179 | -------------------------------------------------------------------------------- /qframelesswindow/mac/window_effect.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import objc 3 | import Cocoa 4 | from PyQt5.QtWidgets import QMacCocoaViewContainer 5 | from PyQt5.QtGui import QColor 6 | from ..utils.mac_utils import getNSWindow 7 | 8 | class MacWindowEffect: 9 | """ Mac OS window effect """ 10 | 11 | def __init__(self, window): 12 | self.window = window 13 | 14 | def setAcrylicEffect(self, hWnd, gradientColor="F2F2F230", isEnableShadow=True, animationId=0): 15 | """ set acrylic effect for window 16 | 17 | Parameter 18 | ---------- 19 | hWnd: int or `sip.voidptr` 20 | window handle 21 | 22 | gradientColor: str 23 | hexadecimal acrylic mixed color, corresponding to RGBA components 24 | 25 | isEnableShadow: bool 26 | whether to enable window shadow 27 | 28 | animationId: int 29 | turn on blur animation or not 30 | """ 31 | frame = Cocoa.NSMakeRect( 32 | 0, 0, self.window.width(), self.window.height()) 33 | visualEffectView = Cocoa.NSVisualEffectView.new() 34 | visualEffectView.setAutoresizingMask_( 35 | Cocoa.NSViewWidthSizable | Cocoa.NSViewHeightSizable) # window resizable 36 | visualEffectView.setFrame_(frame) 37 | visualEffectView.setState_(Cocoa.NSVisualEffectStateActive) 38 | 39 | # https://developer.apple.com/documentation/appkit/nsvisualeffectmaterial 40 | visualEffectView.setMaterial_(Cocoa.NSVisualEffectMaterialPopover) 41 | visualEffectView.setBlendingMode_( 42 | Cocoa.NSVisualEffectBlendingModeBehindWindow) 43 | 44 | nsWindow = getNSWindow(self.window.winId()) 45 | content = nsWindow.contentView() 46 | container = QMacCocoaViewContainer(0, self.window) 47 | content.addSubview_positioned_relativeTo_( 48 | visualEffectView, Cocoa.NSWindowBelow, container) 49 | 50 | def setBorderAccentColor(self, hWnd, color: QColor): 51 | """ Set the border color of the window 52 | 53 | Parameters 54 | ---------- 55 | hWnd: int or `sip.voidptr` 56 | Window handle 57 | 58 | color: QColor 59 | Border Accent color 60 | """ 61 | pass 62 | 63 | def removeBorderAccentColor(self, hWnd): 64 | """ Remove the border color of the window 65 | 66 | Parameters 67 | ---------- 68 | hWnd: int or `sip.voidptr` 69 | Window handle 70 | """ 71 | pass 72 | 73 | def setMicaEffect(self, hWnd, isDarkMode=False, isAlt=False): 74 | """ Add mica effect to the window (Win11 only) 75 | 76 | Parameters 77 | ---------- 78 | hWnd: int or `sip.voidptr` 79 | Window handle 80 | 81 | isDarkMode: bool 82 | whether to use dark mode mica effect 83 | 84 | isAlt: bool 85 | whether to use mica alt effect 86 | """ 87 | self.setAcrylicEffect(hWnd) 88 | 89 | def setAeroEffect(self, hWnd): 90 | """ add Aero effect to the window 91 | 92 | Parameter 93 | ---------- 94 | hWnd: int or `sip.voidptr` 95 | Window handle 96 | """ 97 | self.setAcrylicEffect(hWnd) 98 | 99 | def setTransparentEffect(self, hWnd): 100 | """ set transparent effect for window 101 | 102 | Parameters 103 | ---------- 104 | hWnd : int or `sip.voidptr` 105 | Window handle 106 | """ 107 | pass 108 | 109 | def removeBackgroundEffect(self, hWnd): 110 | """ Remove background effect 111 | 112 | Parameters 113 | ---------- 114 | hWnd : int or `sip.voidptr` 115 | Window handle 116 | """ 117 | pass 118 | 119 | def addShadowEffect(self, hWnd): 120 | """ add shadow to window 121 | 122 | Parameter 123 | ---------- 124 | hWnd: int or `sip.voidptr` 125 | Window handle 126 | """ 127 | getNSWindow(hWnd).setHasShadow_(True) 128 | 129 | def addMenuShadowEffect(self, hWnd): 130 | """ add shadow to menu 131 | 132 | Parameter 133 | ---------- 134 | hWnd: int or `sip.voidptr` 135 | Window handle 136 | """ 137 | self.addShadowEffect(hWnd) 138 | 139 | @staticmethod 140 | def removeMenuShadowEffect(hWnd): 141 | """ Remove shadow from pop-up menu 142 | 143 | Parameters 144 | ---------- 145 | hWnd: int or `sip.voidptr` 146 | Window handle 147 | """ 148 | getNSWindow(hWnd).setHasShadow_(False) 149 | 150 | def removeShadowEffect(self, hWnd): 151 | """ Remove shadow from the window 152 | 153 | Parameters 154 | ---------- 155 | hWnd: int or `sip.voidptr` 156 | Window handle 157 | """ 158 | getNSWindow(hWnd).setHasShadow_(False) 159 | 160 | @staticmethod 161 | def addWindowAnimation(hWnd): 162 | """ Enables the maximize and minimize animation of the window 163 | 164 | Parameters 165 | ---------- 166 | hWnd : int or `sip.voidptr` 167 | Window handle 168 | """ 169 | 170 | @staticmethod 171 | def disableMaximizeButton(hWnd): 172 | """ Disable the maximize button of window 173 | 174 | Parameters 175 | ---------- 176 | hWnd : int or `sip.voidptr` 177 | Window handle 178 | """ 179 | 180 | def enableBlurBehindWindow(self, hWnd): 181 | """ enable the blur effect behind the whole client 182 | Parameters 183 | ---------- 184 | hWnd: int or `sip.voidptr` 185 | Window handle 186 | """ -------------------------------------------------------------------------------- /qframelesswindow/titlebar/__init__.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | 4 | from PyQt5.QtCore import QEvent, Qt 5 | from PyQt5.QtGui import QIcon 6 | from PyQt5.QtWidgets import QHBoxLayout, QLabel, QWidget 7 | 8 | from ..utils import startSystemMove 9 | from .title_bar_buttons import (CloseButton, MaximizeButton, MinimizeButton, 10 | SvgTitleBarButton, TitleBarButton) 11 | 12 | 13 | class TitleBarBase(QWidget): 14 | """ Title bar base class """ 15 | 16 | def __init__(self, parent): 17 | super().__init__(parent) 18 | self.minBtn = MinimizeButton(parent=self) 19 | self.closeBtn = CloseButton(parent=self) 20 | self.maxBtn = MaximizeButton(parent=self) 21 | 22 | self._isDoubleClickEnabled = True 23 | 24 | self.resize(200, 32) 25 | self.setFixedHeight(32) 26 | 27 | # connect signal to slot 28 | self.minBtn.clicked.connect(self.window().showMinimized) 29 | self.maxBtn.clicked.connect(self.__toggleMaxState) 30 | self.closeBtn.clicked.connect(self.window().close) 31 | 32 | self.window().installEventFilter(self) 33 | 34 | def eventFilter(self, obj, e): 35 | if obj is self.window(): 36 | if e.type() == QEvent.WindowStateChange: 37 | self.maxBtn.setMaxState(self.window().isMaximized()) 38 | return False 39 | 40 | return super().eventFilter(obj, e) 41 | 42 | def mouseDoubleClickEvent(self, event): 43 | """ Toggles the maximization state of the window """ 44 | if event.button() != Qt.LeftButton or not self._isDoubleClickEnabled: 45 | return 46 | 47 | self.__toggleMaxState() 48 | 49 | def mouseMoveEvent(self, e): 50 | if sys.platform != "win32" or not self.canDrag(e.pos()): 51 | return 52 | 53 | startSystemMove(self.window(), e.globalPos()) 54 | 55 | def mousePressEvent(self, e): 56 | if sys.platform == "win32" or not self.canDrag(e.pos()): 57 | return 58 | 59 | startSystemMove(self.window(), e.globalPos()) 60 | 61 | def __toggleMaxState(self): 62 | """ Toggles the maximization state of the window and change icon """ 63 | if self.window().isMaximized(): 64 | self.window().showNormal() 65 | else: 66 | self.window().showMaximized() 67 | 68 | if sys.platform == "win32": 69 | from ..utils.win32_utils import releaseMouseLeftButton 70 | releaseMouseLeftButton(self.window().winId()) 71 | 72 | def _isDragRegion(self, pos): 73 | """ Check whether the position belongs to the area where dragging is allowed """ 74 | width = 0 75 | for button in self.findChildren(TitleBarButton): 76 | if button.isVisible(): 77 | width += button.width() 78 | 79 | return 0 < pos.x() < self.width() - width 80 | 81 | def _hasButtonPressed(self): 82 | """ whether any button is pressed """ 83 | return any(btn.isPressed() for btn in self.findChildren(TitleBarButton)) 84 | 85 | def canDrag(self, pos): 86 | """ whether the position is draggable """ 87 | return self._isDragRegion(pos) and not self._hasButtonPressed() 88 | 89 | def setDoubleClickEnabled(self, isEnabled): 90 | """ whether to switch window maximization status when double clicked 91 | 92 | Parameters 93 | ---------- 94 | isEnabled: bool 95 | whether to enable double click 96 | """ 97 | self._isDoubleClickEnabled = isEnabled 98 | 99 | 100 | 101 | class TitleBar(TitleBarBase): 102 | """ Title bar with minimize, maximum and close button """ 103 | 104 | def __init__(self, parent): 105 | super().__init__(parent) 106 | self.hBoxLayout = QHBoxLayout(self) 107 | 108 | # add buttons to layout 109 | self.hBoxLayout.setSpacing(0) 110 | self.hBoxLayout.setContentsMargins(0, 0, 0, 0) 111 | self.hBoxLayout.setAlignment(Qt.AlignVCenter | Qt.AlignLeft) 112 | self.hBoxLayout.addStretch(1) 113 | self.hBoxLayout.addWidget(self.minBtn, 0, Qt.AlignRight) 114 | self.hBoxLayout.addWidget(self.maxBtn, 0, Qt.AlignRight) 115 | self.hBoxLayout.addWidget(self.closeBtn, 0, Qt.AlignRight) 116 | 117 | 118 | class StandardTitleBar(TitleBar): 119 | """ Title bar with icon and title """ 120 | 121 | def __init__(self, parent): 122 | super().__init__(parent) 123 | # add window icon 124 | self.iconLabel = QLabel(self) 125 | self.iconLabel.setFixedSize(20, 20) 126 | self.hBoxLayout.insertSpacing(0, 10) 127 | self.hBoxLayout.insertWidget(1, self.iconLabel, 0, Qt.AlignLeft) 128 | self.window().windowIconChanged.connect(self.setIcon) 129 | 130 | # add title label 131 | self.titleLabel = QLabel(self) 132 | self.hBoxLayout.insertWidget(2, self.titleLabel, 0, Qt.AlignLeft) 133 | self.titleLabel.setStyleSheet(""" 134 | QLabel{ 135 | background: transparent; 136 | font: 13px 'Segoe UI', 'Microsoft YaHei', 'PingFang SC'; 137 | padding: 0 4px 138 | } 139 | """) 140 | self.window().windowTitleChanged.connect(self.setTitle) 141 | 142 | def setTitle(self, title): 143 | """ set the title of title bar 144 | 145 | Parameters 146 | ---------- 147 | title: str 148 | the title of title bar 149 | """ 150 | self.titleLabel.setText(title) 151 | self.titleLabel.adjustSize() 152 | 153 | def setIcon(self, icon): 154 | """ set the icon of title bar 155 | 156 | Parameters 157 | ---------- 158 | icon: QIcon | QPixmap | str 159 | the icon of title bar 160 | """ 161 | self.iconLabel.setPixmap(QIcon(icon).pixmap(20, 20)) 162 | -------------------------------------------------------------------------------- /qframelesswindow/titlebar/title_bar_buttons.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | from enum import Enum 3 | 4 | from PyQt5.QtCore import QFile, QPointF, QRectF, Qt, pyqtProperty 5 | from PyQt5.QtGui import QColor, QPainter, QPainterPath, QPen 6 | from PyQt5.QtWidgets import QAbstractButton 7 | from PyQt5.QtSvg import QSvgRenderer 8 | from PyQt5.QtXml import QDomDocument 9 | 10 | from .._rc import resource 11 | 12 | 13 | class TitleBarButtonState(Enum): 14 | """ Title bar button state """ 15 | NORMAL = 0 16 | HOVER = 1 17 | PRESSED = 2 18 | 19 | 20 | class TitleBarButton(QAbstractButton): 21 | """ Title bar button """ 22 | 23 | def __init__(self, parent=None): 24 | super().__init__(parent=parent) 25 | self.setCursor(Qt.ArrowCursor) 26 | self.setFixedSize(46, 32) 27 | self._state = TitleBarButtonState.NORMAL 28 | 29 | # icon color 30 | self._normalColor = QColor(0, 0, 0) 31 | self._hoverColor = QColor(0, 0, 0) 32 | self._pressedColor = QColor(0, 0, 0) 33 | 34 | # background color 35 | self._normalBgColor = QColor(0, 0, 0, 0) 36 | self._hoverBgColor = QColor(0, 0, 0, 26) 37 | self._pressedBgColor = QColor(0, 0, 0, 51) 38 | 39 | def setState(self, state): 40 | """ set the state of button 41 | 42 | Parameters 43 | ---------- 44 | state: TitleBarButtonState 45 | the state of button 46 | """ 47 | self._state = state 48 | self.update() 49 | 50 | def isPressed(self): 51 | """ whether the button is pressed """ 52 | return self._state == TitleBarButtonState.PRESSED 53 | 54 | def getNormalColor(self): 55 | """ get the icon color of the button in normal state """ 56 | return self._normalColor 57 | 58 | def getHoverColor(self): 59 | """ get the icon color of the button in hover state """ 60 | return self._hoverColor 61 | 62 | def getPressedColor(self): 63 | """ get the icon color of the button in pressed state """ 64 | return self._pressedColor 65 | 66 | def getNormalBackgroundColor(self): 67 | """ get the background color of the button in normal state """ 68 | return self._normalBgColor 69 | 70 | def getHoverBackgroundColor(self): 71 | """ get the background color of the button in hover state """ 72 | return self._hoverBgColor 73 | 74 | def getPressedBackgroundColor(self): 75 | """ get the background color of the button in pressed state """ 76 | return self._pressedBgColor 77 | 78 | def setNormalColor(self, color): 79 | """ set the icon color of the button in normal state 80 | 81 | Parameters 82 | ---------- 83 | color: QColor 84 | icon color 85 | """ 86 | self._normalColor = QColor(color) 87 | self.update() 88 | 89 | def setHoverColor(self, color): 90 | """ set the icon color of the button in hover state 91 | 92 | Parameters 93 | ---------- 94 | color: QColor 95 | icon color 96 | """ 97 | self._hoverColor = QColor(color) 98 | self.update() 99 | 100 | def setPressedColor(self, color): 101 | """ set the icon color of the button in pressed state 102 | 103 | Parameters 104 | ---------- 105 | color: QColor 106 | icon color 107 | """ 108 | self._pressedColor = QColor(color) 109 | self.update() 110 | 111 | def setNormalBackgroundColor(self, color): 112 | """ set the background color of the button in normal state 113 | 114 | Parameters 115 | ---------- 116 | color: QColor 117 | background color 118 | """ 119 | self._normalBgColor = QColor(color) 120 | self.update() 121 | 122 | def setHoverBackgroundColor(self, color): 123 | """ set the background color of the button in hover state 124 | 125 | Parameters 126 | ---------- 127 | color: QColor 128 | background color 129 | """ 130 | self._hoverBgColor = QColor(color) 131 | self.update() 132 | 133 | def setPressedBackgroundColor(self, color): 134 | """ set the background color of the button in pressed state 135 | 136 | Parameters 137 | ---------- 138 | color: QColor 139 | background color 140 | """ 141 | self._pressedBgColor = QColor(color) 142 | self.update() 143 | 144 | def enterEvent(self, e): 145 | self.setState(TitleBarButtonState.HOVER) 146 | super().enterEvent(e) 147 | 148 | def leaveEvent(self, e): 149 | self.setState(TitleBarButtonState.NORMAL) 150 | super().leaveEvent(e) 151 | 152 | def mousePressEvent(self, e): 153 | if e.button() != Qt.LeftButton: 154 | return 155 | 156 | self.setState(TitleBarButtonState.PRESSED) 157 | super().mousePressEvent(e) 158 | 159 | def _getColors(self): 160 | """ get the icon color and background color """ 161 | if self._state == TitleBarButtonState.NORMAL: 162 | return self._normalColor, self._normalBgColor 163 | elif self._state == TitleBarButtonState.HOVER: 164 | return self._hoverColor, self._hoverBgColor 165 | 166 | return self._pressedColor, self._pressedBgColor 167 | 168 | normalColor = pyqtProperty(QColor, getNormalColor, setNormalColor) 169 | hoverColor = pyqtProperty(QColor, getHoverColor, setHoverColor) 170 | pressedColor = pyqtProperty(QColor, getPressedColor, setPressedColor) 171 | normalBackgroundColor = pyqtProperty( 172 | QColor, getNormalBackgroundColor, setNormalBackgroundColor) 173 | hoverBackgroundColor = pyqtProperty( 174 | QColor, getHoverBackgroundColor, setHoverBackgroundColor) 175 | pressedBackgroundColor = pyqtProperty( 176 | QColor, getPressedBackgroundColor, setPressedBackgroundColor) 177 | 178 | 179 | class SvgTitleBarButton(TitleBarButton): 180 | """ Title bar button using svg icon """ 181 | 182 | def __init__(self, iconPath, parent=None): 183 | """ 184 | Parameters 185 | ---------- 186 | iconPath: str 187 | the path of icon 188 | 189 | parent: QWidget 190 | parent widget 191 | """ 192 | super().__init__(parent) 193 | self._svgDom = QDomDocument() 194 | self.setIcon(iconPath) 195 | 196 | def setIcon(self, iconPath): 197 | """ set the icon of button 198 | 199 | Parameters 200 | ---------- 201 | iconPath: str 202 | the path of icon 203 | """ 204 | f = QFile(iconPath) 205 | f.open(QFile.ReadOnly) 206 | self._svgDom.setContent(f.readAll()) 207 | f.close() 208 | 209 | def paintEvent(self, e): 210 | painter = QPainter(self) 211 | painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) 212 | color, bgColor = self._getColors() 213 | 214 | # draw background 215 | painter.setBrush(bgColor) 216 | painter.setPen(Qt.NoPen) 217 | painter.drawRect(self.rect()) 218 | 219 | # draw icon 220 | color = color.name() 221 | pathNodes = self._svgDom.elementsByTagName('path') 222 | for i in range(pathNodes.length()): 223 | element = pathNodes.at(i).toElement() 224 | element.setAttribute('stroke', color) 225 | 226 | renderer = QSvgRenderer(self._svgDom.toByteArray()) 227 | renderer.render(painter, QRectF(self.rect())) 228 | 229 | 230 | class MinimizeButton(TitleBarButton): 231 | """ Minimize button """ 232 | 233 | def paintEvent(self, e): 234 | painter = QPainter(self) 235 | color, bgColor = self._getColors() 236 | 237 | # draw background 238 | painter.setBrush(bgColor) 239 | painter.setPen(Qt.NoPen) 240 | painter.drawRect(self.rect()) 241 | 242 | # draw icon 243 | painter.setBrush(Qt.NoBrush) 244 | pen = QPen(color, 1) 245 | pen.setCosmetic(True) 246 | painter.setPen(pen) 247 | painter.drawLine(18, 16, 28, 16) 248 | 249 | 250 | class MaximizeButton(TitleBarButton): 251 | """ Maximize button """ 252 | 253 | def __init__(self, parent=None): 254 | super().__init__(parent) 255 | self._isMax = False 256 | 257 | def setMaxState(self, isMax): 258 | """ update the maximized state and icon """ 259 | if self._isMax == isMax: 260 | return 261 | 262 | self._isMax = isMax 263 | self.setState(TitleBarButtonState.NORMAL) 264 | 265 | def paintEvent(self, e): 266 | painter = QPainter(self) 267 | color, bgColor = self._getColors() 268 | 269 | # draw background 270 | painter.setBrush(bgColor) 271 | painter.setPen(Qt.NoPen) 272 | painter.drawRect(self.rect()) 273 | 274 | # draw icon 275 | painter.setBrush(Qt.NoBrush) 276 | pen = QPen(color, 1) 277 | pen.setCosmetic(True) 278 | painter.setPen(pen) 279 | 280 | r = self.devicePixelRatioF() 281 | painter.scale(1/r, 1/r) 282 | if not self._isMax: 283 | painter.drawRect(int(18*r), int(11*r), int(10*r), int(10*r)) 284 | else: 285 | painter.drawRect(int(18*r), int(13*r), int(8*r), int(8*r)) 286 | x0 = int(18*r)+int(2*r) 287 | y0 = 13*r 288 | dw = int(2*r) 289 | path = QPainterPath(QPointF(x0, y0)) 290 | path.lineTo(x0, y0-dw) 291 | path.lineTo(x0+8*r, y0-dw) 292 | path.lineTo(x0+8*r, y0-dw+8*r) 293 | path.lineTo(x0+8*r-dw, y0-dw+8*r) 294 | painter.drawPath(path) 295 | 296 | 297 | class CloseButton(SvgTitleBarButton): 298 | """ Close button """ 299 | 300 | def __init__(self, parent=None): 301 | super().__init__(":/qframelesswindow/close.svg", parent) 302 | self.setHoverColor(Qt.white) 303 | self.setPressedColor(Qt.white) 304 | self.setHoverBackgroundColor(QColor(232, 17, 35)) 305 | self.setPressedBackgroundColor(QColor(241, 112, 122)) 306 | -------------------------------------------------------------------------------- /qframelesswindow/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | 4 | if sys.platform == "win32": 5 | from .win32_utils import WindowsMoveResize as MoveResize 6 | from .win32_utils import getSystemAccentColor 7 | from .win32_utils import WindowsScreenCaptureFilter as ScreenCaptureFilter 8 | elif sys.platform == "darwin": 9 | from .mac_utils import MacMoveResize as MoveResize 10 | from .mac_utils import getSystemAccentColor 11 | from .mac_utils import MacScreenCaptureFilter as ScreenCaptureFilter 12 | else: 13 | from .linux_utils import LinuxMoveResize as MoveResize 14 | from .linux_utils import getSystemAccentColor 15 | from .linux_utils import LinuxScreenCaptureFilter as ScreenCaptureFilter 16 | 17 | 18 | def startSystemMove(window, globalPos): 19 | """ resize window 20 | 21 | Parameters 22 | ---------- 23 | window: QWidget 24 | window 25 | 26 | globalPos: QPoint 27 | the global point of mouse release event 28 | """ 29 | MoveResize.startSystemMove(window, globalPos) 30 | 31 | 32 | def starSystemResize(window, globalPos, edges): 33 | """ resize window 34 | 35 | Parameters 36 | ---------- 37 | window: QWidget 38 | window 39 | 40 | globalPos: QPoint 41 | the global point of mouse release event 42 | 43 | edges: `Qt.Edges` 44 | window edges 45 | """ 46 | MoveResize.starSystemResize(window, globalPos, edges) 47 | -------------------------------------------------------------------------------- /qframelesswindow/utils/linux_utils.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from enum import Enum 3 | 4 | import xcffib as xcb 5 | from PyQt5 import sip 6 | from PyQt5.QtCore import QPointF, Qt, QEvent, QPoint, QObject 7 | from PyQt5.QtGui import QMouseEvent, QColor 8 | from PyQt5.QtWidgets import QWidget, QApplication 9 | from PyQt5.QtX11Extras import QX11Info 10 | from xcffib.xproto import (ButtonIndex, ButtonMask, ButtonReleaseEvent, 11 | ClientMessageData, ClientMessageEvent, EventMask, 12 | xprotoExtension) 13 | 14 | 15 | class WindowMessage(Enum): 16 | """ Window message enum class """ 17 | # refer to: https://specifications.freedesktop.org/wm-spec/1.1/x170.html 18 | _NET_WM_MOVERESIZE_SIZE_TOPLEFT = 0 19 | _NET_WM_MOVERESIZE_SIZE_TOP = 1 20 | _NET_WM_MOVERESIZE_SIZE_TOPRIGHT = 2 21 | _NET_WM_MOVERESIZE_SIZE_RIGHT = 3 22 | _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT = 4 23 | _NET_WM_MOVERESIZE_SIZE_BOTTOM = 5 24 | _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT = 6 25 | _NET_WM_MOVERESIZE_SIZE_LEFT = 7 26 | _NET_WM_MOVERESIZE_MOVE = 8 27 | _NET_WM_MOVERESIZE_SIZE_KEYBOARD = 9 28 | _NET_WM_MOVERESIZE_MOVE_KEYBOARD = 10 29 | _NET_WM_MOVERESIZE_CANCEL = 11 30 | 31 | 32 | class LinuxMoveResize: 33 | """ Tool class for moving and resizing window """ 34 | 35 | moveResizeAtom = None 36 | 37 | @classmethod 38 | def sendButtonReleaseEvent(cls, window, globalPos): 39 | """ send button release event 40 | 41 | Parameters 42 | ---------- 43 | window: QWidget 44 | window to be moved or resized 45 | 46 | globalPos: QPoint 47 | the global point of mouse release event 48 | """ 49 | globalPos = QPointF(QPointF(globalPos) * 50 | window.devicePixelRatio()).toPoint() 51 | pos = window.mapFromGlobal(globalPos) 52 | 53 | # open the connection to X server 54 | conn = xcb.wrap(sip.unwrapinstance(QX11Info.connection())) 55 | windowId = int(window.winId()) 56 | xproto = xprotoExtension(conn) 57 | 58 | # refer to: https://www.x.org/releases/X11R7.5/doc/libxcb/tutorial/ 59 | event = ButtonReleaseEvent.synthetic( 60 | detail=ButtonIndex._1, 61 | time=xcb.CurrentTime, 62 | root=QX11Info.appRootWindow(QX11Info.appScreen()), 63 | event=windowId, 64 | child=xcb.NONE, 65 | root_x=globalPos.x(), 66 | root_y=globalPos.y(), 67 | event_x=pos.x(), 68 | event_y=pos.y(), 69 | state=ButtonMask._1, 70 | same_screen=True, 71 | ) 72 | xproto.SendEvent(True, windowId, EventMask.ButtonRelease, event.pack()) 73 | conn.flush() 74 | 75 | @classmethod 76 | def startSystemMoveResize(cls, window, globalPos, message): 77 | """ resize window 78 | 79 | Parameters 80 | ---------- 81 | window: QWidget 82 | window to be moved or resized 83 | 84 | globalPos: QPoint 85 | the global point of mouse release event 86 | 87 | message: int 88 | window message 89 | """ 90 | cls.sendButtonReleaseEvent(window, globalPos) 91 | 92 | globalPos = QPointF(QPointF(globalPos) * 93 | window.devicePixelRatio()).toPoint() 94 | 95 | # open the connection to X server 96 | conn = xcb.wrap(sip.unwrapinstance(QX11Info.connection())) 97 | xproto = xprotoExtension(conn) 98 | 99 | if not cls.moveResizeAtom: 100 | cls.moveResizeAtom = xproto.InternAtom( 101 | False, len("_NET_WM_MOVERESIZE"), "_NET_WM_MOVERESIZE").reply().atom 102 | 103 | union = ClientMessageData.synthetic([ 104 | globalPos.x(), 105 | globalPos.y(), 106 | message, 107 | ButtonIndex._1, 108 | 0 109 | ], "I"*5) 110 | event = ClientMessageEvent.synthetic( 111 | format=32, 112 | window=int(window.winId()), 113 | type=cls.moveResizeAtom, 114 | data=union 115 | ) 116 | xproto.UngrabPointer(xcb.CurrentTime) 117 | xproto.SendEvent( 118 | False, 119 | QX11Info.appRootWindow(QX11Info.appScreen()), 120 | EventMask.SubstructureRedirect | EventMask.SubstructureNotify, 121 | event.pack() 122 | ) 123 | conn.flush() 124 | 125 | @classmethod 126 | def startSystemMove(cls, window, globalPos): 127 | """ move window """ 128 | if QX11Info.isPlatformX11(): 129 | cls.startSystemMoveResize( 130 | window, globalPos, WindowMessage._NET_WM_MOVERESIZE_MOVE.value) 131 | else: 132 | window.windowHandle().startSystemMove() 133 | event = QMouseEvent(QEvent.MouseButtonRelease, QPoint(-1, -1), 134 | Qt.LeftButton, Qt.NoButton, Qt.NoModifier) 135 | QApplication.instance().postEvent(window.windowHandle(), event) 136 | 137 | @classmethod 138 | def starSystemResize(cls, window, globalPos, edges): 139 | """ resize window 140 | 141 | Parameters 142 | ---------- 143 | window: QWidget 144 | window 145 | 146 | globalPos: QPoint 147 | the global point of mouse release event 148 | 149 | edges: `Qt.Edges` 150 | window edges 151 | """ 152 | if not edges: 153 | return 154 | 155 | if QX11Info.isPlatformX11(): 156 | messageMap = { 157 | Qt.TopEdge: WindowMessage._NET_WM_MOVERESIZE_SIZE_TOP, 158 | Qt.TopEdge | Qt.LeftEdge: WindowMessage._NET_WM_MOVERESIZE_SIZE_TOPLEFT, 159 | Qt.TopEdge | Qt.RightEdge: WindowMessage._NET_WM_MOVERESIZE_SIZE_TOPRIGHT, 160 | Qt.BottomEdge: WindowMessage._NET_WM_MOVERESIZE_SIZE_BOTTOM, 161 | Qt.BottomEdge | Qt.LeftEdge: WindowMessage._NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT, 162 | Qt.BottomEdge | Qt.RightEdge: WindowMessage._NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT, 163 | Qt.LeftEdge: WindowMessage._NET_WM_MOVERESIZE_SIZE_LEFT, 164 | Qt.RightEdge: WindowMessage._NET_WM_MOVERESIZE_SIZE_RIGHT, 165 | } 166 | cls.startSystemMoveResize(window, globalPos, messageMap[edges].value) 167 | else: 168 | window.windowHandle().startSystemResize(edges) 169 | 170 | 171 | def getSystemAccentColor(): 172 | """ get the accent color of system 173 | 174 | Returns 175 | ------- 176 | color: QColor 177 | accent color 178 | """ 179 | return QColor() 180 | 181 | 182 | class LinuxScreenCaptureFilter(QObject): 183 | """ Filter for screen capture """ 184 | 185 | def __init__(self, parent: QWidget): 186 | super().__init__(parent) 187 | self.setScreenCaptureEnabled(False) 188 | 189 | def eventFilter(self, watched, event): 190 | if watched == self.parent(): 191 | if event.type() == QEvent.Type.WinIdChange: 192 | self.setScreenCaptureEnabled(self.isScreenCaptureEnabled) 193 | 194 | return super().eventFilter(watched, event) 195 | 196 | def setScreenCaptureEnabled(self, enabled: bool): 197 | """ Set screen capture enabled """ 198 | self.isScreenCaptureEnabled = enabled 199 | -------------------------------------------------------------------------------- /qframelesswindow/utils/mac_utils.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | from ctypes import c_void_p 3 | 4 | import Cocoa 5 | import objc 6 | from PyQt5.QtCore import QT_VERSION_STR, QEvent, QObject 7 | from PyQt5.QtGui import QColor 8 | from PyQt5.QtWidgets import QWidget 9 | from Quartz.CoreGraphics import (CGEventCreateMouseEvent, 10 | kCGEventLeftMouseDown, kCGMouseButtonLeft) 11 | 12 | QT_VERSION = tuple(int(v) for v in QT_VERSION_STR.split('.')) 13 | 14 | 15 | class MacMoveResize: 16 | """ Tool class for moving and resizing Mac OS window """ 17 | 18 | @staticmethod 19 | def startSystemMove(window: QWidget, globalPos): 20 | """ resize window 21 | 22 | Parameters 23 | ---------- 24 | window: QWidget 25 | window 26 | 27 | globalPos: QPoint 28 | the global point of mouse release event 29 | """ 30 | if QT_VERSION >= (5, 15, 0): 31 | window.windowHandle().startSystemMove() 32 | return 33 | 34 | nsWindow = getNSWindow(window.winId()) 35 | 36 | # send click event 37 | cgEvent = CGEventCreateMouseEvent( 38 | None, kCGEventLeftMouseDown, (globalPos.x(), globalPos.y()), kCGMouseButtonLeft) 39 | clickEvent = Cocoa.NSEvent.eventWithCGEvent_(cgEvent) 40 | 41 | if clickEvent: 42 | nsWindow.performWindowDragWithEvent_(clickEvent) 43 | 44 | # CFRelease(cgEvent) 45 | 46 | @classmethod 47 | def starSystemResize(cls, window, globalPos, edges): 48 | """ resize window 49 | 50 | Parameters 51 | ---------- 52 | window: QWidget 53 | window 54 | 55 | globalPos: QPoint 56 | the global point of mouse release event 57 | 58 | edges: `Qt.Edges` 59 | window edges 60 | """ 61 | pass 62 | 63 | 64 | def getNSWindow(winId): 65 | """ convert window handle to NSWindow 66 | 67 | Parameters 68 | ---------- 69 | winId: int or `sip.voidptr` 70 | window handle 71 | """ 72 | view = objc.objc_object(c_void_p=c_void_p(int(winId))) 73 | return view.window() 74 | 75 | 76 | def getSystemAccentColor(): 77 | """ get the accent color of system 78 | 79 | Returns 80 | ------- 81 | color: QColor 82 | accent color 83 | """ 84 | color = Cocoa.NSColor.controlAccentColor() 85 | color = color.colorUsingColorSpace_(Cocoa.NSColorSpace.sRGBColorSpace()) 86 | r = int(color.redComponent() * 255) 87 | g = int(color.greenComponent() * 255) 88 | b = int(color.blueComponent() * 255) 89 | return QColor(r, g, b) 90 | 91 | 92 | class MacScreenCaptureFilter(QObject): 93 | """ Filter for screen capture """ 94 | 95 | def __init__(self, parent: QWidget): 96 | super().__init__(parent) 97 | self.setScreenCaptureEnabled(False) 98 | 99 | def eventFilter(self, watched, event): 100 | if watched == self.parent(): 101 | if event.type() == QEvent.Type.WinIdChange: 102 | self.setScreenCaptureEnabled(self.isScreenCaptureEnabled) 103 | 104 | return super().eventFilter(watched, event) 105 | 106 | def setScreenCaptureEnabled(self, enabled: bool): 107 | """ Set screen capture enabled """ 108 | self.isScreenCaptureEnabled = enabled 109 | 110 | nsWindow = getNSWindow(self.parent().winId()) 111 | if nsWindow: 112 | NSWindowSharingNone = 0 113 | NSWindowSharingReadOnly = 1 114 | nsWindow.setSharingType_(NSWindowSharingReadOnly if enabled else NSWindowSharingNone) 115 | -------------------------------------------------------------------------------- /qframelesswindow/utils/win32_utils.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | import warnings 4 | from ctypes import Structure, byref, sizeof, windll, c_int, c_ulong, c_bool, POINTER, WinDLL, wintypes 5 | from ctypes.wintypes import DWORD, HWND, LPARAM, RECT, UINT 6 | from platform import platform 7 | from winreg import OpenKey, HKEY_CURRENT_USER, KEY_READ, QueryValueEx, CloseKey 8 | 9 | import win32api 10 | import win32con 11 | import win32gui 12 | import win32print 13 | from PyQt5.QtCore import QOperatingSystemVersion, QObject, QEvent 14 | from PyQt5.QtGui import QGuiApplication, QColor 15 | from PyQt5.QtWidgets import QWidget 16 | from win32comext.shell import shellcon 17 | 18 | 19 | def getSystemAccentColor(): 20 | """ get the accent color of system 21 | 22 | Returns 23 | ------- 24 | color: QColor 25 | accent color 26 | """ 27 | DwmGetColorizationColor = windll.dwmapi.DwmGetColorizationColor 28 | DwmGetColorizationColor.restype = c_ulong 29 | DwmGetColorizationColor.argtypes = [POINTER(c_ulong), POINTER(c_bool)] 30 | 31 | color = c_ulong() 32 | code = DwmGetColorizationColor(byref(color), byref(c_bool())) 33 | 34 | if code != 0: 35 | warnings.warn("Unable to obtain system accent color.") 36 | return QColor() 37 | 38 | return QColor(color.value) 39 | 40 | 41 | def isSystemBorderAccentEnabled(): 42 | """ Check whether the border accent is enabled """ 43 | if not isGreaterEqualWin11(): 44 | return False 45 | 46 | try: 47 | key = OpenKey(HKEY_CURRENT_USER, r"SOFTWARE\Microsoft\Windows\DWM", 0, KEY_READ) 48 | value, _ = QueryValueEx(key, "ColorPrevalence") 49 | CloseKey(key) 50 | 51 | return bool(value) 52 | except: 53 | return False 54 | 55 | 56 | def isMaximized(hWnd): 57 | """ Determine whether the window is maximized 58 | 59 | Parameters 60 | ---------- 61 | hWnd: int or `sip.voidptr` 62 | window handle 63 | """ 64 | windowPlacement = win32gui.GetWindowPlacement(hWnd) 65 | if not windowPlacement: 66 | return False 67 | 68 | return windowPlacement[1] == win32con.SW_MAXIMIZE 69 | 70 | 71 | def isFullScreen(hWnd): 72 | """ Determine whether the window is full screen 73 | 74 | Parameters 75 | ---------- 76 | hWnd: int or `sip.voidptr` 77 | window handle 78 | """ 79 | if not hWnd: 80 | return False 81 | 82 | hWnd = int(hWnd) 83 | winRect = win32gui.GetWindowRect(hWnd) 84 | if not winRect: 85 | return False 86 | 87 | monitorInfo = getMonitorInfo(hWnd, win32con.MONITOR_DEFAULTTOPRIMARY) 88 | if not monitorInfo: 89 | return False 90 | 91 | monitorRect = monitorInfo["Monitor"] 92 | return all(i == j for i, j in zip(winRect, monitorRect)) 93 | 94 | 95 | def isCompositionEnabled(): 96 | """ detect if dwm composition is enabled """ 97 | bResult = c_int(0) 98 | windll.dwmapi.DwmIsCompositionEnabled(byref(bResult)) 99 | return bool(bResult.value) 100 | 101 | 102 | def getMonitorInfo(hWnd, dwFlags): 103 | """ get monitor info, return `None` if failed 104 | 105 | Parameters 106 | ---------- 107 | hWnd: int or `sip.voidptr` 108 | window handle 109 | 110 | dwFlags: int 111 | Determines the return value if the window does not intersect any display monitor 112 | """ 113 | monitor = win32api.MonitorFromWindow(hWnd, dwFlags) 114 | if not monitor: 115 | return 116 | 117 | return win32api.GetMonitorInfo(monitor) 118 | 119 | 120 | def getResizeBorderThickness(hWnd, horizontal=True): 121 | """ get resize border thickness of widget 122 | 123 | Parameters 124 | ---------- 125 | hWnd: int or `sip.voidptr` 126 | window handle 127 | 128 | dpiScale: bool 129 | whether to use dpi scale 130 | """ 131 | window = findWindow(hWnd) 132 | if not window: 133 | return 0 134 | 135 | frame = win32con.SM_CXSIZEFRAME if horizontal else win32con.SM_CYSIZEFRAME 136 | result = getSystemMetrics(hWnd, frame, horizontal) + getSystemMetrics(hWnd, 92, horizontal) 137 | 138 | if result > 0: 139 | return result 140 | 141 | thickness = 8 if isCompositionEnabled() else 4 142 | return round(thickness*window.devicePixelRatio()) 143 | 144 | 145 | def getSystemMetrics(hWnd, index, horizontal): 146 | """ get system metrics """ 147 | if not hasattr(windll.user32, 'GetSystemMetricsForDpi'): 148 | return win32api.GetSystemMetrics(index) 149 | 150 | dpi = getDpiForWindow(hWnd, horizontal) 151 | return windll.user32.GetSystemMetricsForDpi(index, dpi) 152 | 153 | 154 | def getDpiForWindow(hWnd, horizontal=True): 155 | """ get dpi for window 156 | 157 | Parameters 158 | ---------- 159 | hWnd: int or `sip.voidptr` 160 | window handle 161 | 162 | dpiScale: bool 163 | whether to use dpi scale 164 | """ 165 | if hasattr(windll.user32, 'GetDpiForWindow'): 166 | windll.user32.GetDpiForWindow.argtypes = [HWND] 167 | windll.user32.GetDpiForWindow.restype = UINT 168 | return windll.user32.GetDpiForWindow(hWnd) 169 | 170 | hdc = win32gui.GetDC(hWnd) 171 | if not hdc: 172 | return 96 173 | 174 | dpiX = win32print.GetDeviceCaps(hdc, win32con.LOGPIXELSX) 175 | dpiY = win32print.GetDeviceCaps(hdc, win32con.LOGPIXELSY) 176 | win32gui.ReleaseDC(hWnd, hdc) 177 | if dpiX > 0 and horizontal: 178 | return dpiX 179 | elif dpiY > 0 and not horizontal: 180 | return dpiY 181 | 182 | return 96 183 | 184 | 185 | def findWindow(hWnd): 186 | """ find window by hWnd, return `None` if not found 187 | 188 | Parameters 189 | ---------- 190 | hWnd: int or `sip.voidptr` 191 | window handle 192 | """ 193 | if not hWnd: 194 | return 195 | 196 | windows = QGuiApplication.topLevelWindows() 197 | if not windows: 198 | return 199 | 200 | hWnd = int(hWnd) 201 | for window in windows: 202 | if window and int(window.winId()) == hWnd: 203 | return window 204 | 205 | 206 | def isGreaterEqualVersion(version): 207 | """ determine if the windows version ≥ the specifics version 208 | 209 | Parameters 210 | ---------- 211 | version: QOperatingSystemVersion 212 | windows version 213 | """ 214 | return QOperatingSystemVersion.current() >= version 215 | 216 | 217 | def isGreaterEqualWin8_1(): 218 | """ determine if the windows version ≥ Win8.1 """ 219 | return isGreaterEqualVersion(QOperatingSystemVersion.Windows8_1) 220 | 221 | 222 | def isGreaterEqualWin10(): 223 | """ determine if the windows version ≥ Win10 """ 224 | return isGreaterEqualVersion(QOperatingSystemVersion.Windows10) 225 | 226 | 227 | def isGreaterEqualWin11(): 228 | """ determine if the windows version ≥ Win10 """ 229 | return isGreaterEqualVersion(QOperatingSystemVersion.Windows10) and sys.getwindowsversion().build >= 22000 230 | 231 | 232 | def isWin7(): 233 | """ determine if the windows version is Win7 """ 234 | return "Windows-7" in platform() 235 | 236 | 237 | def releaseMouseLeftButton(hWnd, x=0, y=0): 238 | """ release mouse left button at (x, y) 239 | 240 | Parameters 241 | ---------- 242 | hWnd: int or `sip.voidptr` 243 | window handle 244 | 245 | x: int 246 | mouse x pos 247 | 248 | y: int 249 | mouse y pos 250 | """ 251 | lp = (y & 0xFFFF) << 16 | (x & 0xFFFF) 252 | win32api.SendMessage(int(hWnd), win32con.WM_LBUTTONUP, 0, lp) 253 | 254 | 255 | class APPBARDATA(Structure): 256 | _fields_ = [ 257 | ('cbSize', DWORD), 258 | ('hWnd', HWND), 259 | ('uCallbackMessage', UINT), 260 | ('uEdge', UINT), 261 | ('rc', RECT), 262 | ('lParam', LPARAM), 263 | ] 264 | 265 | 266 | class Taskbar: 267 | 268 | LEFT = 0 269 | TOP = 1 270 | RIGHT = 2 271 | BOTTOM = 3 272 | NO_POSITION = 4 273 | 274 | AUTO_HIDE_THICKNESS = 2 275 | 276 | @staticmethod 277 | def isAutoHide(): 278 | """ detect whether the taskbar is hidden automatically """ 279 | appbarData = APPBARDATA(sizeof(APPBARDATA), 0, 280 | 0, 0, RECT(0, 0, 0, 0), 0) 281 | taskbarState = windll.shell32.SHAppBarMessage( 282 | shellcon.ABM_GETSTATE, byref(appbarData)) 283 | 284 | return taskbarState == shellcon.ABS_AUTOHIDE 285 | 286 | @classmethod 287 | def getPosition(cls, hWnd): 288 | """ get the position of auto-hide task bar 289 | 290 | Parameters 291 | ---------- 292 | hWnd: int or `sip.voidptr` 293 | window handle 294 | """ 295 | if isGreaterEqualWin8_1(): 296 | monitorInfo = getMonitorInfo( 297 | hWnd, win32con.MONITOR_DEFAULTTONEAREST) 298 | if not monitorInfo: 299 | return cls.NO_POSITION 300 | 301 | monitor = RECT(*monitorInfo['Monitor']) 302 | appbarData = APPBARDATA(sizeof(APPBARDATA), 0, 0, 0, monitor, 0) 303 | positions = [cls.LEFT, cls.TOP, cls.RIGHT, cls.BOTTOM] 304 | for position in positions: 305 | appbarData.uEdge = position 306 | if windll.shell32.SHAppBarMessage(11, byref(appbarData)): 307 | return position 308 | 309 | return cls.NO_POSITION 310 | 311 | appbarData = APPBARDATA(sizeof(APPBARDATA), win32gui.FindWindow( 312 | "Shell_TrayWnd", None), 0, 0, RECT(0, 0, 0, 0), 0) 313 | if appbarData.hWnd: 314 | windowMonitor = win32api.MonitorFromWindow( 315 | hWnd, win32con.MONITOR_DEFAULTTONEAREST) 316 | if not windowMonitor: 317 | return cls.NO_POSITION 318 | 319 | taskbarMonitor = win32api.MonitorFromWindow( 320 | appbarData.hWnd, win32con.MONITOR_DEFAULTTOPRIMARY) 321 | if not taskbarMonitor: 322 | return cls.NO_POSITION 323 | 324 | if taskbarMonitor == windowMonitor: 325 | windll.shell32.SHAppBarMessage( 326 | shellcon.ABM_GETTASKBARPOS, byref(appbarData)) 327 | return appbarData.uEdge 328 | 329 | return cls.NO_POSITION 330 | 331 | 332 | class WindowsMoveResize: 333 | """ Tool class for moving and resizing Mac OS window """ 334 | 335 | @staticmethod 336 | def startSystemMove(window, globalPos): 337 | """ resize window 338 | 339 | Parameters 340 | ---------- 341 | window: QWidget 342 | window 343 | 344 | globalPos: QPoint 345 | the global point of mouse release event 346 | """ 347 | win32gui.ReleaseCapture() 348 | win32api.SendMessage( 349 | int(window.winId()), 350 | win32con.WM_SYSCOMMAND, 351 | win32con.SC_MOVE | win32con.HTCAPTION, 352 | 0 353 | ) 354 | 355 | @classmethod 356 | def starSystemResize(cls, window, globalPos, edges): 357 | """ resize window 358 | 359 | Parameters 360 | ---------- 361 | window: QWidget 362 | window 363 | 364 | globalPos: QPoint 365 | the global point of mouse release event 366 | 367 | edges: `Qt.Edges` 368 | window edges 369 | """ 370 | pass 371 | 372 | 373 | class WindowsScreenCaptureFilter(QObject): 374 | """ Filter for screen capture """ 375 | 376 | def __init__(self, parent: QWidget): 377 | super().__init__(parent) 378 | self.setScreenCaptureEnabled(False) 379 | 380 | def eventFilter(self, watched, event): 381 | if watched == self.parent(): 382 | if event.type() == QEvent.Type.WinIdChange: 383 | self.setScreenCaptureEnabled(self.isScreenCaptureEnabled) 384 | 385 | return super().eventFilter(watched, event) 386 | 387 | def setScreenCaptureEnabled(self, enabled: bool): 388 | """ Set screen capture enabled """ 389 | self.isScreenCaptureEnabled = enabled 390 | WDA_NONE = 0x00000000 391 | WDA_EXCLUDEFROMCAPTURE = 0x00000011 392 | 393 | user32 = WinDLL('user32', use_last_error=True) 394 | SetWindowDisplayAffinity = user32.SetWindowDisplayAffinity 395 | SetWindowDisplayAffinity.argtypes = (wintypes.HWND, wintypes.DWORD) 396 | SetWindowDisplayAffinity.restype = wintypes.BOOL 397 | 398 | SetWindowDisplayAffinity(int(self.parent().winId()), WDA_NONE if enabled else WDA_EXCLUDEFROMCAPTURE) 399 | -------------------------------------------------------------------------------- /qframelesswindow/webengine/__init__.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | import sys 3 | 4 | from PyQt5.QtCore import Qt 5 | from PyQt5.QtWebEngineWidgets import QWebEngineView 6 | from qframelesswindow import AcrylicWindow, FramelessWindow 7 | 8 | 9 | class FramelessWebEngineView(QWebEngineView): 10 | """ Frameless web engine view """ 11 | 12 | def __init__(self, parent): 13 | if sys.platform == "win32" and isinstance(parent.window(), AcrylicWindow): 14 | parent.window().setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) 15 | 16 | super().__init__(parent=parent) 17 | self.setHtml("") 18 | 19 | if isinstance(self.window(), FramelessWindow): 20 | self.window().updateFrameless() -------------------------------------------------------------------------------- /qframelesswindow/windows/__init__.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | from ctypes import cast 4 | from ctypes.wintypes import LPRECT, MSG 5 | 6 | import win32api 7 | import win32con 8 | import win32gui 9 | from PyQt5.QtCore import Qt, QSize, QRect 10 | from PyQt5.QtGui import QCloseEvent, QCursor 11 | from PyQt5.QtWidgets import QApplication, QWidget 12 | 13 | from ..titlebar import TitleBar 14 | from ..utils import win32_utils as win_utils 15 | from ..utils.win32_utils import Taskbar, isSystemBorderAccentEnabled, getSystemAccentColor 16 | from .c_structures import LPNCCALCSIZE_PARAMS 17 | from .window_effect import WindowsWindowEffect 18 | 19 | 20 | class WindowsFramelessWindow(QWidget): 21 | """ Frameless window for Windows system """ 22 | 23 | BORDER_WIDTH = 5 24 | 25 | def __init__(self, parent=None): 26 | super().__init__(parent=parent) 27 | self.windowEffect = WindowsWindowEffect(self) 28 | self.titleBar = TitleBar(self) 29 | self._isSystemButtonVisible = False 30 | self._isResizeEnabled = True 31 | 32 | self.updateFrameless() 33 | 34 | # solve issue #5 35 | self.windowHandle().screenChanged.connect(self.__onScreenChanged) 36 | 37 | self.resize(500, 500) 38 | self.titleBar.raise_() 39 | 40 | def updateFrameless(self): 41 | """ update frameless window """ 42 | stayOnTop = Qt.WindowStaysOnTopHint if self.windowFlags() & Qt.WindowStaysOnTopHint else 0 43 | 44 | if not win_utils.isWin7(): 45 | self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint) 46 | elif self.parent(): 47 | self.setWindowFlags(self.parent().windowFlags() | Qt.FramelessWindowHint | Qt.WindowMinMaxButtonsHint | stayOnTop) 48 | else: 49 | self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowMinMaxButtonsHint | stayOnTop) 50 | 51 | # add DWM shadow and window animation 52 | self.windowEffect.addWindowAnimation(self.winId()) 53 | if not isinstance(self, AcrylicWindow): 54 | self.windowEffect.addShadowEffect(self.winId()) 55 | 56 | def setTitleBar(self, titleBar): 57 | """ set custom title bar 58 | 59 | Parameters 60 | ---------- 61 | titleBar: TitleBar 62 | title bar 63 | """ 64 | self.titleBar.deleteLater() 65 | self.titleBar.hide() 66 | self.titleBar = titleBar 67 | self.titleBar.setParent(self) 68 | self.titleBar.raise_() 69 | 70 | def setResizeEnabled(self, isEnabled: bool): 71 | """ set whether resizing is enabled """ 72 | self._isResizeEnabled = isEnabled 73 | 74 | def setStayOnTop(self, isTop: bool): 75 | """ set the stay on top status """ 76 | if isTop: 77 | self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint) 78 | else: 79 | self.setWindowFlags(self.windowFlags() & ~Qt.WindowStaysOnTopHint) 80 | 81 | self.updateFrameless() 82 | self.show() 83 | 84 | def toggleStayOnTop(self): 85 | """ toggle the stay on top status """ 86 | if self.windowFlags() & Qt.WindowStaysOnTopHint: 87 | self.setStayOnTop(False) 88 | else: 89 | self.setStayOnTop(True) 90 | 91 | def resizeEvent(self, e): 92 | super().resizeEvent(e) 93 | self.titleBar.resize(self.width(), self.titleBar.height()) 94 | 95 | def isSystemButtonVisible(self): 96 | """ Returns whether the system title bar button is visible """ 97 | return self._isSystemButtonVisible 98 | 99 | def setSystemTitleBarButtonVisible(self, isVisible): 100 | """ set the visibility of system title bar button, only works for macOS """ 101 | pass 102 | 103 | def systemTitleBarRect(self, size: QSize) -> QRect: 104 | """ Returns the system title bar rect, only works for macOS 105 | 106 | Parameters 107 | ---------- 108 | size: QSize 109 | original system title bar rect 110 | """ 111 | return QRect(0, 0, size.width(), size.height()) 112 | 113 | def nativeEvent(self, eventType, message): 114 | """ Handle the Windows message """ 115 | msg = MSG.from_address(message.__int__()) 116 | if not msg.hWnd: 117 | return super().nativeEvent(eventType, message) 118 | 119 | if msg.message == win32con.WM_NCHITTEST and self._isResizeEnabled: 120 | xPos, yPos = win32gui.ScreenToClient(msg.hWnd, win32api.GetCursorPos()) 121 | clientRect = win32gui.GetClientRect(msg.hWnd) 122 | 123 | w = clientRect[2] - clientRect[0] 124 | h = clientRect[3] - clientRect[1] 125 | 126 | # fixes issue https://github.com/zhiyiYo/PyQt-Frameless-Window/issues/98 127 | bw = 0 if win_utils.isMaximized(msg.hWnd) or win_utils.isFullScreen(msg.hWnd) else self.BORDER_WIDTH 128 | lx = xPos < bw # left 129 | rx = xPos > w - bw # right 130 | ty = yPos < bw # top 131 | by = yPos > h - bw # bottom 132 | if lx and ty: 133 | return True, win32con.HTTOPLEFT 134 | elif rx and by: 135 | return True, win32con.HTBOTTOMRIGHT 136 | elif rx and ty: 137 | return True, win32con.HTTOPRIGHT 138 | elif lx and by: 139 | return True, win32con.HTBOTTOMLEFT 140 | elif ty: 141 | return True, win32con.HTTOP 142 | elif by: 143 | return True, win32con.HTBOTTOM 144 | elif lx: 145 | return True, win32con.HTLEFT 146 | elif rx: 147 | return True, win32con.HTRIGHT 148 | elif msg.message == win32con.WM_NCCALCSIZE: 149 | if msg.wParam: 150 | rect = cast(msg.lParam, LPNCCALCSIZE_PARAMS).contents.rgrc[0] 151 | else: 152 | rect = cast(msg.lParam, LPRECT).contents 153 | 154 | isMax = win_utils.isMaximized(msg.hWnd) 155 | isFull = win_utils.isFullScreen(msg.hWnd) 156 | 157 | # adjust the size of client rect 158 | if isMax and not isFull: 159 | ty = win_utils.getResizeBorderThickness(msg.hWnd, False) 160 | rect.top += ty 161 | rect.bottom -= ty 162 | 163 | tx = win_utils.getResizeBorderThickness(msg.hWnd, True) 164 | rect.left += tx 165 | rect.right -= tx 166 | 167 | # handle the situation that an auto-hide taskbar is enabled 168 | if (isMax or isFull) and Taskbar.isAutoHide(): 169 | position = Taskbar.getPosition(msg.hWnd) 170 | if position == Taskbar.LEFT: 171 | rect.top += Taskbar.AUTO_HIDE_THICKNESS 172 | elif position == Taskbar.BOTTOM: 173 | rect.bottom -= Taskbar.AUTO_HIDE_THICKNESS 174 | elif position == Taskbar.LEFT: 175 | rect.left += Taskbar.AUTO_HIDE_THICKNESS 176 | elif position == Taskbar.RIGHT: 177 | rect.right -= Taskbar.AUTO_HIDE_THICKNESS 178 | 179 | result = 0 if not msg.wParam else win32con.WVR_REDRAW 180 | return True, result 181 | elif msg.message == win32con.WM_SETFOCUS and isSystemBorderAccentEnabled(): 182 | self.windowEffect.setBorderAccentColor(self.winId(), getSystemAccentColor()) 183 | return True, 0 184 | elif msg.message == win32con.WM_KILLFOCUS: 185 | self.windowEffect.removeBorderAccentColor(self.winId()) 186 | return True, 0 187 | 188 | return super().nativeEvent(eventType, message) 189 | 190 | def __onScreenChanged(self): 191 | hWnd = int(self.windowHandle().winId()) 192 | win32gui.SetWindowPos(hWnd, None, 0, 0, 0, 0, win32con.SWP_NOMOVE | 193 | win32con.SWP_NOSIZE | win32con.SWP_FRAMECHANGED) 194 | 195 | 196 | class AcrylicWindow(WindowsFramelessWindow): 197 | """ A frameless window with acrylic effect """ 198 | 199 | def __init__(self, parent=None): 200 | super().__init__(parent=parent) 201 | self.__closedByKey = False 202 | self.setStyleSheet("AcrylicWindow{background:transparent}") 203 | 204 | def updateFrameless(self): 205 | super().updateFrameless() 206 | self.windowEffect.enableBlurBehindWindow(self.winId()) 207 | 208 | stayOnTop = Qt.WindowStaysOnTopHint if self.windowFlags() & Qt.WindowStaysOnTopHint else 0 209 | 210 | if win_utils.isWin7() and self.parent(): 211 | self.setWindowFlags(self.parent().windowFlags() | Qt.FramelessWindowHint | Qt.WindowMinMaxButtonsHint | stayOnTop) 212 | else: 213 | self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowMinMaxButtonsHint | stayOnTop) 214 | 215 | self.windowEffect.addWindowAnimation(self.winId()) 216 | 217 | if win_utils.isWin7(): 218 | self.windowEffect.addShadowEffect(self.winId()) 219 | self.windowEffect.setAeroEffect(self.winId()) 220 | else: 221 | self.windowEffect.setAcrylicEffect(self.winId()) 222 | if win_utils.isGreaterEqualWin11(): 223 | self.windowEffect.addShadowEffect(self.winId()) 224 | 225 | def nativeEvent(self, eventType, message): 226 | """ Handle the Windows message """ 227 | msg = MSG.from_address(message.__int__()) 228 | 229 | # handle Alt+F4 230 | if msg.message == win32con.WM_SYSKEYDOWN: 231 | if msg.wParam == win32con.VK_F4: 232 | self.__closedByKey = True 233 | QApplication.sendEvent(self, QCloseEvent()) 234 | return False, 0 235 | 236 | return super().nativeEvent(eventType, message) 237 | 238 | def closeEvent(self, e): 239 | if not self.__closedByKey or QApplication.quitOnLastWindowClosed(): 240 | self.__closedByKey = False 241 | return super().closeEvent(e) 242 | 243 | # system tray icon 244 | self.__closedByKey = False 245 | self.hide() 246 | -------------------------------------------------------------------------------- /qframelesswindow/windows/c_structures.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | from ctypes import POINTER, Structure, c_int 3 | from ctypes.wintypes import DWORD, HWND, ULONG, POINT, RECT, UINT, BOOL, HRGN 4 | from enum import Enum 5 | 6 | 7 | class WINDOWCOMPOSITIONATTRIB(Enum): 8 | WCA_UNDEFINED = 0 9 | WCA_NCRENDERING_ENABLED = 1 10 | WCA_NCRENDERING_POLICY = 2 11 | WCA_TRANSITIONS_FORCEDISABLED = 3 12 | WCA_ALLOW_NCPAINT = 4 13 | WCA_CAPTION_BUTTON_BOUNDS = 5 14 | WCA_NONCLIENT_RTL_LAYOUT = 6 15 | WCA_FORCE_ICONIC_REPRESENTATION = 7 16 | WCA_EXTENDED_FRAME_BOUNDS = 8 17 | WCA_HAS_ICONIC_BITMAP = 9 18 | WCA_THEME_ATTRIBUTES = 10 19 | WCA_NCRENDERING_EXILED = 11 20 | WCA_NCADORNMENTINFO = 12 21 | WCA_EXCLUDED_FROM_LIVEPREVIEW = 13 22 | WCA_VIDEO_OVERLAY_ACTIVE = 14 23 | WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15 24 | WCA_DISALLOW_PEEK = 16 25 | WCA_CLOAK = 17 26 | WCA_CLOAKED = 18 27 | WCA_ACCENT_POLICY = 19 28 | WCA_FREEZE_REPRESENTATION = 20 29 | WCA_EVER_UNCLOAKED = 21 30 | WCA_VISUAL_OWNER = 22 31 | WCA_HOLOGRAPHIC = 23 32 | WCA_EXCLUDED_FROM_DDA = 24 33 | WCA_PASSIVEUPDATEMODE = 25 34 | WCA_USEDARKMODECOLORS = 26 35 | WCA_CORNER_STYLE = 27 36 | WCA_PART_COLOR = 28 37 | WCA_DISABLE_MOVESIZE_FEEDBACK = 29 38 | WCA_LAST = 30 39 | 40 | 41 | class ACCENT_STATE(Enum): 42 | """ Client area status enumeration class """ 43 | ACCENT_DISABLED = 0 44 | ACCENT_ENABLE_GRADIENT = 1 45 | ACCENT_ENABLE_TRANSPARENTGRADIENT = 2 46 | ACCENT_ENABLE_BLURBEHIND = 3 # Aero effect 47 | ACCENT_ENABLE_ACRYLICBLURBEHIND = 4 # Acrylic effect 48 | ACCENT_ENABLE_HOSTBACKDROP = 5 # Mica effect 49 | ACCENT_INVALID_STATE = 6 50 | 51 | 52 | class ACCENT_POLICY(Structure): 53 | """ Specific attributes of client area """ 54 | 55 | _fields_ = [ 56 | ("AccentState", DWORD), 57 | ("AccentFlags", DWORD), 58 | ("GradientColor", DWORD), 59 | ("AnimationId", DWORD), 60 | ] 61 | 62 | 63 | class WINDOWCOMPOSITIONATTRIBDATA(Structure): 64 | _fields_ = [ 65 | ("Attribute", DWORD), 66 | # Pointer() receives any ctypes type and returns a pointer type 67 | ("Data", POINTER(ACCENT_POLICY)), 68 | ("SizeOfData", ULONG), 69 | ] 70 | 71 | 72 | class DWMNCRENDERINGPOLICY(Enum): 73 | DWMNCRP_USEWINDOWSTYLE = 0 74 | DWMNCRP_DISABLED = 1 75 | DWMNCRP_ENABLED = 2 76 | DWMNCRP_LAS = 3 77 | 78 | 79 | class DWMWINDOWATTRIBUTE(Enum): 80 | DWMWA_NCRENDERING_ENABLED = 1 81 | DWMWA_NCRENDERING_POLICY = 2 82 | DWMWA_TRANSITIONS_FORCEDISABLED = 3 83 | DWMWA_ALLOW_NCPAINT = 4 84 | DWMWA_CAPTION_BUTTON_BOUNDS = 5 85 | DWMWA_NONCLIENT_RTL_LAYOUT = 6 86 | DWMWA_FORCE_ICONIC_REPRESENTATION = 7 87 | DWMWA_FLIP3D_POLICY = 8 88 | DWMWA_EXTENDED_FRAME_BOUNDS = 9 89 | DWMWA_HAS_ICONIC_BITMAP = 10 90 | DWMWA_DISALLOW_PEEK = 11 91 | DWMWA_EXCLUDED_FROM_PEEK = 12 92 | DWMWA_CLOAK = 13 93 | DWMWA_CLOAKED = 14 94 | DWMWA_FREEZE_REPRESENTATION = 15 95 | DWMWA_PASSIVE_UPDATE_MODE = 16 96 | DWMWA_USE_HOSTBACKDROPBRUSH = 17 97 | DWMWA_USE_IMMERSIVE_DARK_MODE = 20 98 | DWMWA_WINDOW_CORNER_PREFERENCE = 33 99 | DWMWA_BORDER_COLOR = 34 100 | DWMWA_CAPTION_COLOR = 35 101 | DWMWA_TEXT_COLOR = 36 102 | DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37 103 | DWMWA_SYSTEMBACKDROP_TYPE = 38 104 | DWMWA_LAST = 39 105 | 106 | 107 | class MARGINS(Structure): 108 | _fields_ = [ 109 | ("cxLeftWidth", c_int), 110 | ("cxRightWidth", c_int), 111 | ("cyTopHeight", c_int), 112 | ("cyBottomHeight", c_int), 113 | ] 114 | 115 | 116 | class MINMAXINFO(Structure): 117 | _fields_ = [ 118 | ("ptReserved", POINT), 119 | ("ptMaxSize", POINT), 120 | ("ptMaxPosition", POINT), 121 | ("ptMinTrackSize", POINT), 122 | ("ptMaxTrackSize", POINT), 123 | ] 124 | 125 | 126 | class PWINDOWPOS(Structure): 127 | _fields_ = [ 128 | ('hWnd', HWND), 129 | ('hwndInsertAfter', HWND), 130 | ('x', c_int), 131 | ('y', c_int), 132 | ('cx', c_int), 133 | ('cy', c_int), 134 | ('flags', UINT) 135 | ] 136 | 137 | 138 | class NCCALCSIZE_PARAMS(Structure): 139 | _fields_ = [ 140 | ('rgrc', RECT*3), 141 | ('lppos', POINTER(PWINDOWPOS)) 142 | ] 143 | 144 | 145 | LPNCCALCSIZE_PARAMS = POINTER(NCCALCSIZE_PARAMS) 146 | 147 | 148 | class DWM_BLURBEHIND(Structure): 149 | _fields_ = [ 150 | ('dwFlags', DWORD), 151 | ('fEnable', BOOL), 152 | ('hRgnBlur', HRGN), 153 | ('fTransitionOnMaximized', BOOL), 154 | ] 155 | -------------------------------------------------------------------------------- /qframelesswindow/windows/window_effect.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | import warnings 4 | from ctypes import POINTER, byref, c_bool, c_int, pointer, sizeof, WinDLL 5 | from ctypes.wintypes import DWORD, LONG, LPCVOID 6 | 7 | import win32api 8 | import win32con 9 | import win32gui 10 | from PyQt5.QtGui import QColor 11 | 12 | from .c_structures import (ACCENT_POLICY, ACCENT_STATE, DWMNCRENDERINGPOLICY, 13 | DWMWINDOWATTRIBUTE, MARGINS, 14 | WINDOWCOMPOSITIONATTRIB, 15 | WINDOWCOMPOSITIONATTRIBDATA, DWM_BLURBEHIND) 16 | from ..utils.win32_utils import isGreaterEqualWin10, isGreaterEqualWin11, isCompositionEnabled 17 | 18 | 19 | class WindowsWindowEffect: 20 | """ Windows window effect """ 21 | 22 | def __init__(self, window): 23 | self.window = window 24 | 25 | # Declare the function signature of the API 26 | self.user32 = WinDLL("user32") 27 | self.dwmapi = WinDLL("dwmapi") 28 | self.SetWindowCompositionAttribute = self.user32.SetWindowCompositionAttribute 29 | self.DwmExtendFrameIntoClientArea = self.dwmapi.DwmExtendFrameIntoClientArea 30 | self.DwmEnableBlurBehindWindow = self.dwmapi.DwmEnableBlurBehindWindow 31 | self.DwmSetWindowAttribute = self.dwmapi.DwmSetWindowAttribute 32 | 33 | self.SetWindowCompositionAttribute.restype = c_bool 34 | self.DwmExtendFrameIntoClientArea.restype = LONG 35 | self.DwmEnableBlurBehindWindow.restype = LONG 36 | self.DwmSetWindowAttribute.restype = LONG 37 | 38 | self.SetWindowCompositionAttribute.argtypes = [ 39 | c_int, 40 | POINTER(WINDOWCOMPOSITIONATTRIBDATA), 41 | ] 42 | self.DwmSetWindowAttribute.argtypes = [c_int, DWORD, LPCVOID, DWORD] 43 | self.DwmExtendFrameIntoClientArea.argtypes = [c_int, POINTER(MARGINS)] 44 | self.DwmEnableBlurBehindWindow.argtypes = [c_int, POINTER(DWM_BLURBEHIND)] 45 | 46 | # Initialize structure 47 | self.accentPolicy = ACCENT_POLICY() 48 | self.winCompAttrData = WINDOWCOMPOSITIONATTRIBDATA() 49 | self.winCompAttrData.Attribute = WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY.value 50 | self.winCompAttrData.SizeOfData = sizeof(self.accentPolicy) 51 | self.winCompAttrData.Data = pointer(self.accentPolicy) 52 | 53 | def setAcrylicEffect(self, hWnd, gradientColor="F2F2F299", enableShadow=True, animationId=0): 54 | """ Add the acrylic effect to the window 55 | 56 | Parameters 57 | ---------- 58 | hWnd: int or `sip.voidptr` 59 | Window handle 60 | 61 | gradientColor: str 62 | Hexadecimal acrylic mixed color, corresponding to four RGBA channels 63 | 64 | isEnableShadow: bool 65 | Enable window shadows 66 | 67 | animationId: int 68 | Turn on matte animation 69 | """ 70 | if not isGreaterEqualWin10(): 71 | warnings.warn("The acrylic effect is only available on Win10+") 72 | return 73 | 74 | hWnd = int(hWnd) 75 | gradientColor = ''.join(gradientColor[i:i+2] for i in range(6, -1, -2)) 76 | gradientColor = DWORD(int(gradientColor, base=16)) 77 | animationId = DWORD(animationId) 78 | accentFlags = DWORD(0x20 | 0x40 | 0x80 | 0x100) if enableShadow else DWORD(0) 79 | self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_ENABLE_ACRYLICBLURBEHIND.value 80 | self.accentPolicy.GradientColor = gradientColor 81 | self.accentPolicy.AccentFlags = accentFlags 82 | self.accentPolicy.AnimationId = animationId 83 | self.winCompAttrData.Attribute = WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY.value 84 | self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData)) 85 | 86 | def setBorderAccentColor(self, hWnd, color: QColor): 87 | """ Set the border color of the window 88 | 89 | Parameters 90 | ---------- 91 | hWnd: int or `sip.voidptr` 92 | Window handle 93 | 94 | color: QColor 95 | Border Accent color 96 | """ 97 | if not isGreaterEqualWin11(): 98 | return 99 | 100 | hWnd = int(hWnd) 101 | colorref = DWORD(color.red() | (color.green() << 8) | (color.blue() << 16)) 102 | self.DwmSetWindowAttribute(hWnd, 103 | DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR.value, 104 | byref(colorref), 105 | 4) 106 | 107 | def removeBorderAccentColor(self, hWnd): 108 | """ Remove the border color of the window 109 | 110 | Parameters 111 | ---------- 112 | hWnd: int or `sip.voidptr` 113 | Window handle 114 | """ 115 | if not isGreaterEqualWin11(): 116 | return 117 | 118 | hWnd = int(hWnd) 119 | self.DwmSetWindowAttribute(hWnd, 120 | DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR.value, 121 | byref(DWORD(0xFFFFFFFF)), 122 | 4) 123 | 124 | def setMicaEffect(self, hWnd, isDarkMode=False, isAlt=False): 125 | """ Add the mica effect to the window (Win11 only) 126 | 127 | Parameters 128 | ---------- 129 | hWnd: int or `sip.voidptr` 130 | Window handle 131 | 132 | isDarkMode: bool 133 | whether to use dark mode mica effect 134 | 135 | isAlt: bool 136 | whether to enable mica alt effect 137 | """ 138 | if not isGreaterEqualWin11(): 139 | warnings.warn("The mica effect is only available on Win11") 140 | return 141 | 142 | hWnd = int(hWnd) 143 | # fix issue #125 144 | margins = MARGINS(16777215, 16777215, 0, 0) 145 | self.DwmExtendFrameIntoClientArea(hWnd, byref(margins)) 146 | 147 | self.winCompAttrData.Attribute = WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY.value 148 | self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_ENABLE_HOSTBACKDROP.value 149 | self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData)) 150 | 151 | if isDarkMode: 152 | self.winCompAttrData.Attribute = WINDOWCOMPOSITIONATTRIB.WCA_USEDARKMODECOLORS.value 153 | self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData)) 154 | 155 | if sys.getwindowsversion().build < 22523: 156 | self.DwmSetWindowAttribute(hWnd, 1029, byref(c_int(1)), 4) 157 | else: 158 | self.DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE.value, byref(c_int(4 if isAlt else 2)), 4) 159 | 160 | self.DwmSetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE.value, byref(c_int(1*isDarkMode)), 4) 161 | 162 | def setAeroEffect(self, hWnd): 163 | """ Add the aero effect to the window 164 | 165 | Parameters 166 | ---------- 167 | hWnd: int or `sip.voidptr` 168 | Window handle 169 | """ 170 | hWnd = int(hWnd) 171 | self.winCompAttrData.Attribute = WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY.value 172 | self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_ENABLE_BLURBEHIND.value 173 | self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData)) 174 | 175 | def removeBackgroundEffect(self, hWnd): 176 | """ Remove background effect 177 | 178 | Parameters 179 | ---------- 180 | hWnd: int or `sip.voidptr` 181 | Window handle 182 | """ 183 | hWnd = int(hWnd) 184 | self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_DISABLED.value 185 | self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData)) 186 | 187 | def addShadowEffect(self, hWnd): 188 | """ Add DWM shadow to window 189 | 190 | Parameters 191 | ---------- 192 | hWnd: int or `sip.voidptr` 193 | Window handle 194 | """ 195 | if not isCompositionEnabled(): 196 | return 197 | 198 | hWnd = int(hWnd) 199 | margins = MARGINS(-1, -1, -1, -1) 200 | self.DwmExtendFrameIntoClientArea(hWnd, byref(margins)) 201 | 202 | def addMenuShadowEffect(self, hWnd): 203 | """ Add DWM shadow to menu 204 | 205 | Parameters 206 | ---------- 207 | hWnd: int or `sip.voidptr` 208 | Window handle 209 | """ 210 | if not isCompositionEnabled(): 211 | return 212 | 213 | hWnd = int(hWnd) 214 | self.DwmSetWindowAttribute( 215 | hWnd, 216 | DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY.value, 217 | byref(c_int(DWMNCRENDERINGPOLICY.DWMNCRP_ENABLED.value)), 218 | 4, 219 | ) 220 | margins = MARGINS(-1, -1, -1, -1) 221 | self.DwmExtendFrameIntoClientArea(hWnd, byref(margins)) 222 | 223 | def removeShadowEffect(self, hWnd): 224 | """ Remove DWM shadow from the window 225 | 226 | Parameters 227 | ---------- 228 | hWnd: int or `sip.voidptr` 229 | Window handle 230 | """ 231 | hWnd = int(hWnd) 232 | self.DwmSetWindowAttribute( 233 | hWnd, 234 | DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY.value, 235 | byref(c_int(DWMNCRENDERINGPOLICY.DWMNCRP_DISABLED.value)), 236 | 4, 237 | ) 238 | 239 | @staticmethod 240 | def removeMenuShadowEffect(hWnd): 241 | """ Remove shadow from pop-up menu 242 | 243 | Parameters 244 | ---------- 245 | hWnd: int or `sip.voidptr` 246 | Window handle 247 | """ 248 | hWnd = int(hWnd) 249 | style = win32gui.GetClassLong(hWnd, win32con.GCL_STYLE) 250 | style &= ~0x00020000 # CS_DROPSHADOW 251 | win32api.SetClassLong(hWnd, win32con.GCL_STYLE, style) 252 | 253 | @staticmethod 254 | def addWindowAnimation(hWnd): 255 | """ Enables the maximize and minimize animation of the window 256 | 257 | Parameters 258 | ---------- 259 | hWnd : int or `sip.voidptr` 260 | Window handle 261 | """ 262 | hWnd = int(hWnd) 263 | style = win32gui.GetWindowLong(hWnd, win32con.GWL_STYLE) 264 | win32gui.SetWindowLong( 265 | hWnd, 266 | win32con.GWL_STYLE, 267 | style 268 | | win32con.WS_MINIMIZEBOX 269 | | win32con.WS_MAXIMIZEBOX 270 | | win32con.WS_CAPTION 271 | | win32con.CS_DBLCLKS 272 | | win32con.WS_THICKFRAME, 273 | ) 274 | 275 | @staticmethod 276 | def disableMaximizeButton(hWnd): 277 | """ Disable the maximize button of window 278 | 279 | Parameters 280 | ---------- 281 | hWnd : int or `sip.voidptr` 282 | Window handle 283 | """ 284 | hWnd = int(hWnd) 285 | style = win32gui.GetWindowLong(hWnd, win32con.GWL_STYLE) 286 | win32gui.SetWindowLong( 287 | hWnd, 288 | win32con.GWL_STYLE, 289 | style & ~win32con.WS_MAXIMIZEBOX, 290 | ) 291 | 292 | def enableBlurBehindWindow(self, hWnd): 293 | """ enable the blur effect behind the whole client 294 | Parameters 295 | ---------- 296 | hWnd: int or `sip.voidptr` 297 | Window handle 298 | """ 299 | blurBehind = DWM_BLURBEHIND(1, True, 0, False) 300 | self.DwmEnableBlurBehindWindow(int(hWnd), byref(blurBehind)) 301 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pywin32==227 ; sys_platform=="win32" 2 | xcffib==0.11.1; sys_platform=="linux" 3 | pyobjc ; sys_platform=="darwin" 4 | PyCocoa ; sys_platform=="darwin" -------------------------------------------------------------------------------- /screenshot/acrylic_window.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/screenshot/acrylic_window.jpg -------------------------------------------------------------------------------- /screenshot/cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/screenshot/cover.jpg -------------------------------------------------------------------------------- /screenshot/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/screenshot/logo.png -------------------------------------------------------------------------------- /screenshot/normal_frameless_window.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/screenshot/normal_frameless_window.gif -------------------------------------------------------------------------------- /screenshot/shoko.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhiyiYo/PyQt-Frameless-Window/16f82e09cb1f468206fe8e622df7aaa5f6577873/screenshot/shoko.png -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | 4 | with open('README.md', encoding='utf-8') as f: 5 | long_description = f.read() 6 | 7 | setuptools.setup( 8 | name="PyQt5-Frameless-Window", 9 | version="0.7.3", 10 | keywords="pyqt frameless", 11 | author="zhiyiYo", 12 | author_email="shokokawaii@outlook.com", 13 | description="A cross-platform frameless window based on pyqt5, support Win32, X11, Wayland and macOS.", 14 | long_description=long_description, 15 | long_description_content_type='text/markdown', 16 | license="GPLv3", 17 | url="https://github.com/zhiyiYo/PyQt-Frameless-Window", 18 | packages=setuptools.find_packages(), 19 | install_requires=[ 20 | "pywin32;platform_system=='Windows'", 21 | "xcffib;platform_system=='Linux'", 22 | "pyobjc;platform_system=='Darwin'", 23 | "PyCocoa;platform_system=='Darwin'", 24 | ], 25 | classifiers=[ 26 | 'Programming Language :: Python :: 3', 27 | 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 28 | 'Operating System :: OS Independent' 29 | ] 30 | ) 31 | --------------------------------------------------------------------------------