Repository: la-vie-est-belle/qtbox Branch: master Commit: 1775b0e22b93 Files: 160 Total size: 400.4 KB Directory structure: gitextract_6wyvheni/ ├── .github/ │ └── FUNDING.yml ├── .gitignore ├── CHANGELOG ├── LICENSE ├── README.md └── src/ └── qtbox/ ├── __init__.py ├── demo/ │ ├── __init__.py │ ├── checkbox/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ ├── demo1.py │ │ │ └── demo2.py │ │ └── style/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ ├── demo2.py │ │ ├── demo3.py │ │ └── demo4.py │ ├── combobox/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ ├── demo1.py │ │ │ └── demo2.py │ │ └── style/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ ├── demo2.py │ │ └── demo3.py │ ├── dial/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ └── demo1.py │ │ └── style/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ └── demo2.py │ ├── label/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ ├── demo1.py │ │ │ ├── demo2.py │ │ │ ├── demo3.py │ │ │ ├── demo4.py │ │ │ ├── demo5.py │ │ │ ├── demo6.py │ │ │ └── demo7.py │ │ └── style/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ ├── demo2.py │ │ ├── demo3.py │ │ └── demo4.py │ ├── lcdnumber/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ ├── demo1.py │ │ │ ├── demo2.py │ │ │ └── demo3.py │ │ └── style/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ ├── demo2.py │ │ ├── demo3.py │ │ ├── demo4.py │ │ └── demo5.py │ ├── lineedit/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ ├── demo1.py │ │ │ ├── demo2.py │ │ │ ├── demo3.py │ │ │ ├── demo4.py │ │ │ └── demo5.py │ │ └── style/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ ├── demo2.py │ │ ├── demo3.py │ │ ├── demo4.py │ │ ├── demo5.py │ │ ├── demo6.py │ │ └── demo7.py │ ├── listwidget/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ └── demo1.py │ │ └── style/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ └── demo2.py │ ├── progressbar/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ ├── demo1.py │ │ │ └── demo2.py │ │ └── style/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ ├── demo2.py │ │ ├── demo3.py │ │ ├── demo4.py │ │ ├── demo5.py │ │ ├── demo6.py │ │ ├── demo7.py │ │ ├── demo8.py │ │ └── demo9.py │ ├── pushbutton/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ ├── demo1.py │ │ │ ├── demo2.py │ │ │ └── demo3.py │ │ └── style/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ ├── demo10.py │ │ ├── demo11.py │ │ ├── demo12.py │ │ ├── demo2.py │ │ ├── demo3.py │ │ ├── demo4.py │ │ ├── demo5.py │ │ ├── demo6.py │ │ ├── demo7.py │ │ ├── demo8.py │ │ └── demo9.py │ ├── slider/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ └── demo1.py │ │ └── style/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ ├── demo2.py │ │ ├── demo3.py │ │ ├── demo4.py │ │ └── demo5.py │ ├── spinbox/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ └── demo1.py │ │ └── style/ │ │ ├── __init__.py │ │ └── demo1.py │ ├── tablewidget/ │ │ ├── __init__.py │ │ ├── func/ │ │ │ ├── __init__.py │ │ │ ├── demo1.py │ │ │ └── demo2.py │ │ └── style/ │ │ ├── __init__.py │ │ └── demo1.py │ └── widget/ │ ├── __init__.py │ ├── func/ │ │ ├── __init__.py │ │ ├── demo1.py │ │ └── demo2.py │ └── style/ │ ├── __init__.py │ ├── demo1.py │ └── demo2.py ├── gui/ │ ├── __init__.py │ ├── editor.py │ ├── menu.py │ ├── message.py │ ├── title.py │ ├── viewer.py │ └── window.py ├── main.py ├── res/ │ ├── completion.txt │ ├── config.json │ └── qss/ │ ├── black/ │ │ ├── editor.qss │ │ ├── menu.qss │ │ ├── message_box.qss │ │ ├── title.qss │ │ ├── viewer.qss │ │ └── window_body.qss │ └── white/ │ ├── editor.qss │ ├── menu.qss │ ├── message_box.qss │ ├── title.qss │ ├── viewer.qss │ └── window_body.qss └── utils/ ├── __init__.py ├── check.py └── output.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/FUNDING.yml ================================================ custom: ['https://www.paypal.com/paypalme/louisren666', 'https://pic4.zhimg.com/v2-6cad70f5aeeb9cc1a8a95c66b36a7ab7_r.jpg'] ================================================ FILE: .gitignore ================================================ __pycache__ dist .idea .DS_Store pyproject.toml ================================================ FILE: CHANGELOG ================================================ v1.2.0 1. Fixed known bugs. 2. Updated the project structure. 3. Added C++/Qt code for each demo. 4. Adapted to high resolution screen. Thank @panhaovue for the tip. v1.1.5 1. Fixed icon size. 2. Made window resizable. 3. Added exe for users without Python environment. v1.1.4 1. Added 1 style demo and 2 func demos for QTableWidget. 2. Enriched widget choices in QSS Editor. 3. Optimized suppress_stdout_stderr() in output.py. 4. Eliminate the framework's QSS effect (e.g. QScrollBar's QSS effect) on demos. v1.1.3 1. Added 1 func demo for QLineEdit. 2. Added 1 func demo for QWidget. 3. Added a sponsor part. 4. Fixed a crash problem. v1.1.2 1. Added 1 style demo for QListWidget. 2. Added 1 style demo for QPushButton. 3. Added new version release notice. 4. Fixed known issues of QSS Editor. v1.1.1 1. Added 1 func demo for QLabel. 2. Added 1 style demo for QPushButton. 3. Added 1 style demo and 1 func demo for QListWidget. 4. Fixed crash problem when showing QDial, QProgress and QPushButton style demos. v1.1.0 1. Added QSS Editor. 2. Added 2 style demos and 1 func demo for QWidget. v1.0.0 1. Added 4 style demos and 2 func demos for QCheckBox. 2. Added 3 style demos and 2 func demos for QComboBox. 3. Added 3 style demos and 1 func demo for QDial. 4. Added 4 style demos and 6 func demos for QLabel. 5. Added 5 style demos and 3 func demos for QLCDNumber. 6. Added 7 style demos and 4 func demos for QLineEdit. 7. Added 9 style demos and 2 func demos for QProgressBar. 8. Added 10 style demos and 3 func demos for QPushButton. 9. Added 5 style demos and 1 func demo for QSlider. 10. Added 1 style demo and 1 func demo for QSpinBox. 11. Added two themes: white and black. ================================================ FILE: LICENSE ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: README.md ================================================ # Qt Box ([中文](https://zhuanlan.zhihu.com/p/606612591))

Qt Box contains many common and useful PyQt & PySide & C++/Qt widget demos, which may save your time during development. ## Installation ```markdown pip install qtbox ``` ## How to use Open a command window and use command `qtbox` to show Qt Box GUI. Right-click on a widget shown in the Style tab or Function tab, then you can view or download the code. When viewing the code, you can click on the switch button to show PyQt, PySide or C++/Qt code. On the main window, click on the switch button to change the window theme. Click on the edit button or type `qtbox-qss` in the command window to open QSS Editor. ## For C++ Qt users If you don't have a Python environment, download [QtBox.zip](https://la-vie-est-belle.github.io/qtbox/Qt%20Box.zip) which includes `qtbox.exe` executable file. ## Support author Support author to make this project better. Thanks a lot. :) - [PayPal](https://www.paypal.com/paypalme/louisren666) - [WeChat or AliPay](https://pic4.zhimg.com/v2-6cad70f5aeeb9cc1a8a95c66b36a7ab7_r.jpg) ## Other links - [Github](https://github.com/la-vie-est-belle/qtbox) - [CSDN](https://blog.csdn.net/La_vie_est_belle/article/details/129037040) - [Bilibili](https://space.bilibili.com/414891732) - [知乎](https://zhuanlan.zhihu.com/p/606612591) - [PyPi](https://pypi.org/project/qtbox/) ================================================ FILE: src/qtbox/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/checkbox/__init__.py ================================================ from .func import demo1, demo2 from .style import demo1, demo2, demo3, demo4 ================================================ FILE: src/qtbox/demo/checkbox/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/checkbox/func/demo1.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QCheckBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QCheckBox = createWidgetMenuBase(QCheckBox) class QtBoxFuncCheckBox1(QCheckBox): def __init__(self): super(QtBoxFuncCheckBox1, self).__init__(str(Path(__file__))) self.setTristate(True) self.setText("UnChecked") self.stateChanged.connect(self.update_text) def update_text(self): if self.checkState() == Qt.Unchecked: self.setText("UnChecked") elif self.checkState() == Qt.PartiallyChecked: self.setText("PartiallyChecked") elif self.checkState() == Qt.Checked: self.setText("Checked") # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QCheckBox # class QtBoxFuncCheckBox1(QCheckBox): # def __init__(self): # super(QtBoxFuncCheckBox1, self).__init__() # self.setTristate(True) # self.setText("UnChecked") # self.stateChanged.connect(self.update_text) # def update_text(self): # if self.checkState() == Qt.Unchecked: # self.setText("UnChecked") # elif self.checkState() == Qt.PartiallyChecked: # self.setText("PartiallyChecked") # elif self.checkState() == Qt.Checked: # self.setText("Checked") # PySide # C++/Qt # #ifndef QTBOXFUNCCHECKBOX1_H # #define QTBOXFUNCCHECKBOX1_H # #include # class QtBoxFuncCheckBox1 : public QCheckBox # { # Q_OBJECT # public: # QtBoxFuncCheckBox1(QWidget *parent = nullptr); # private slots: # void updateText(); # }; # #endif // QTBOXFUNCCHECKBOX1_H # #include "qtboxfunccheckbox1.h" # #include # QtBoxFuncCheckBox1::QtBoxFuncCheckBox1(QWidget *parent) # : QCheckBox(parent) # { # setTristate(true); # setText("UnChecked"); # connect(this, SIGNAL(stateChanged(int)), this, SLOT(updateText())); # } # void QtBoxFuncCheckBox1::updateText() # { # if (checkState() == Qt::Unchecked) { # setText("UnChecked"); # } # else if (checkState() == Qt::PartiallyChecked) { # setText("PartiallyChecked"); # } # else if (checkState() == Qt::Checked) { # setText("Checked"); # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/checkbox/func/demo2.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QCheckBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QCheckBox = createWidgetMenuBase(QCheckBox) class QtBoxFuncCheckBox2(QCheckBox): def __init__(self): super(QtBoxFuncCheckBox2, self).__init__(str(Path(__file__))) self.setText("Text on the left") self.setLayoutDirection(Qt.RightToLeft) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QCheckBox # class QtBoxFuncCheckBox2(QCheckBox): # def __init__(self): # super(QtBoxFuncCheckBox2, self).__init__() # self.setText("Text on the left") # self.setLayoutDirection(Qt.RightToLeft) # PySide # C++/Qt # #ifndef QTBOXFUNCCHECKBOX2_H # #define QTBOXFUNCCHECKBOX2_H # #include # class QtBoxFuncCheckBox2 : public QCheckBox # { # Q_OBJECT # public: # QtBoxFuncCheckBox2(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCCHECKBOX2_H # #include "qtboxfunccheckbox2.h" # #include # QtBoxFuncCheckBox2::QtBoxFuncCheckBox2(QWidget *parent) # : QCheckBox(parent) # { # setText("Text on the left"); # setLayoutDirection(Qt::RightToLeft); # } # C++/Qt ================================================ FILE: src/qtbox/demo/checkbox/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/checkbox/style/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QCheckBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QCheckBox = createWidgetMenuBase(QCheckBox) PATH_TO_IMG1 = str(Path(__file__).parent.parent.parent.parent / "res/images/close.png").replace("\\", "/") PATH_TO_IMG2 = str(Path(__file__).parent.parent.parent.parent / "res/images/minimize.png").replace("\\", "/") PATH_TO_IMG3 = str(Path(__file__).parent.parent.parent.parent / "res/images/check.png").replace("\\", "/") class QtBoxStyleCheckBox1(QCheckBox): def __init__(self): super(QtBoxStyleCheckBox1, self).__init__(str(Path(__file__))) self.setText("Qt Box") self.setTristate(True) self.setStyleSheet(""" QCheckBox { spacing: 5px; font-size: 15px; font-weight: bold; } QCheckBox::indicator { width: 16px; height: 16px; border: 2px solid black; border-radius: 6px; } QCheckBox::indicator:unchecked { image: url(%s); background-color: black; } QCheckBox::indicator:indeterminate { image: url(%s); background-color: black; } QCheckBox::indicator:checked { image: url(%s); background-color: black; } """ % (PATH_TO_IMG1, PATH_TO_IMG2, PATH_TO_IMG3)) # PyQt # PySide # from PySide2.QtWidgets import QCheckBox # class QtBoxStyleCheckBox1(QCheckBox): # def __init__(self): # super(QtBoxStyleCheckBox1, self).__init__() # self.setText("Qt Box") # self.setTristate(True) # self.setStyleSheet(""" # QCheckBox { # spacing: 5px; # font-size: 15px; # font-weight: bold; # } # QCheckBox::indicator { # width: 16px; # height: 16px; # border: 2px solid black; # border-radius: 6px; # } # QCheckBox::indicator:unchecked { # image: url(%s); # background-color: black; # } # QCheckBox::indicator:indeterminate { # image: url(%s); # background-color: black; # } # QCheckBox::indicator:checked { # image: url(%s); # background-color: black; # } # """ % (PATH_TO_IMG1, PATH_TO_IMG2, PATH_TO_IMG3)) # PySide # C++/Qt # #ifndef QTBOXSTYLECHECKBOX1_H # #define QTBOXSTYLECHECKBOX1_H # #include # class QtBoxStyleCheckBox1 : public QCheckBox # { # Q_OBJECT # public: # QtBoxStyleCheckBox1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLECHECKBOX1_H # #include "qtboxstylecheckbox1.h" # QtBoxStyleCheckBox1::QtBoxStyleCheckBox1(QWidget *parent) # : QCheckBox(parent) # { # setText("Qt Box"); # setTristate(true); # setStyleSheet(R"( # QCheckBox { # spacing: 5px; # font-size: 15px; # font-weight: bold; # } # QCheckBox::indicator { # width: 16px; # height: 16px; # border: 2px solid black; # border-radius: 6px; # } # QCheckBox::indicator:unchecked { # image: url(PATH_TO_IMG); # background-color: black; # } # QCheckBox::indicator:indeterminate { # image: url(PATH_TO_IMG); # background-color: black; # } # QCheckBox::indicator:checked { # image: url(PATH_TO_IMG); # background-color: black; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/checkbox/style/demo2.py ================================================ # PyQt from PyQt5.QtWidgets import QCheckBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QCheckBox = createWidgetMenuBase(QCheckBox) PATH_TO_IMG1 = str(Path(__file__).parent.parent.parent.parent / "res/images/switch_off.png").replace("\\", "/") PATH_TO_IMG2 = str(Path(__file__).parent.parent.parent.parent / "res/images/switch_on.png").replace("\\", "/") class QtBoxStyleCheckBox2(QCheckBox): def __init__(self): super(QtBoxStyleCheckBox2, self).__init__(str(Path(__file__))) self.setText("Qt Box") self.setStyleSheet(""" QCheckBox { font-size: 15px; } QCheckBox::indicator { padding-top: 1px; width: 40px; height: 30px; border: none; } QCheckBox::indicator:unchecked { image: url(%s); } QCheckBox::indicator:checked { image: url(%s); } """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PyQt # PySide # from PySide2.QtWidgets import QCheckBox # class QtBoxStyleCheckBox2(QCheckBox): # def __init__(self): # super(QtBoxStyleCheckBox2, self).__init__() # self.setText("Qt Box") # self.setStyleSheet(""" # QCheckBox { # font-size: 15px; # } # QCheckBox::indicator { # padding-top: 1px; # width: 40px; # height: 30px; # border: none; # } # QCheckBox::indicator:unchecked { # image: url(%s); # } # QCheckBox::indicator:checked { # image: url(%s); # } # """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PySide # C++/Qt # #ifndef QTBOXSTYLECHECKBOX2_H # #define QTBOXSTYLECHECKBOX2_H # #include # class QtBoxStyleCheckBox2 : public QCheckBox # { # Q_OBJECT # public: # QtBoxStyleCheckBox2(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLECHECKBOX2_H # #include "qtboxstylecheckbox2.h" # QtBoxStyleCheckBox2::QtBoxStyleCheckBox2(QWidget *parent) # : QCheckBox(parent) # { # setText("Qt Box"); # setStyleSheet(R"( # QCheckBox { # font-size: 15px; # } # QCheckBox::indicator { # padding-top: 1px; # width: 40px; # height: 30px; # border: none; # } # QCheckBox::indicator:unchecked { # image: url(PATH_TO_IMG); # } # QCheckBox::indicator:checked { # image: url(PATH_TO_IMG); # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/checkbox/style/demo3.py ================================================ # PyQt from PyQt5.QtWidgets import QCheckBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QCheckBox = createWidgetMenuBase(QCheckBox) PATH_TO_IMG1 = str(Path(__file__).parent.parent.parent.parent / "res/images/off.png").replace("\\", "/") PATH_TO_IMG2 = str(Path(__file__).parent.parent.parent.parent / "res/images/on.png").replace("\\", "/") class QtBoxStyleCheckBox3(QCheckBox): def __init__(self): super(QtBoxStyleCheckBox3, self).__init__(str(Path(__file__))) self.setText("Qt Box") self.setStyleSheet(""" QCheckBox { font-size: 15px; } QCheckBox::indicator { width: 30px; height: 30px; border: none; } QCheckBox::indicator:unchecked { image: url(%s); } QCheckBox::indicator:checked { image: url(%s); } """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PyQt # PySide # from PySide2.QtWidgets import QCheckBox # class QtBoxStyleCheckBox3(QCheckBox): # def __init__(self): # super(QtBoxStyleCheckBox3, self).__init__() # self.setText("Qt Box") # self.setStyleSheet(""" # QCheckBox { # font-size: 15px; # } # QCheckBox::indicator { # width: 30px; # height: 30px; # border: none; # } # QCheckBox::indicator:unchecked { # image: url(%s); # } # QCheckBox::indicator:checked { # image: url(%s); # } # """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PySide # C++/Qt # #ifndef QTBOXSTYLECHECKBOX3_H # #define QTBOXSTYLECHECKBOX3_H # #include # class QtBoxStyleCheckBox3 : public QCheckBox # { # Q_OBJECT # public: # QtBoxStyleCheckBox3(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLECHECKBOX3_H # #include "qtboxstylecheckbox3.h" # QtBoxStyleCheckBox3::QtBoxStyleCheckBox3(QWidget *parent) # : QCheckBox(parent) # { # setText("Qt Box"); # setStyleSheet(R"( # QCheckBox { # font-size: 15px; # } # QCheckBox::indicator { # width: 30px; # height: 30px; # border: none; # } # QCheckBox::indicator:unchecked { # image: url(PATH_TO_IMG); # } # QCheckBox::indicator:checked { # image: url(PATH_TO_IMG); # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/checkbox/style/demo4.py ================================================ # PyQt from PyQt5.QtWidgets import QCheckBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QCheckBox = createWidgetMenuBase(QCheckBox) PATH_TO_IMG1 = str(Path(__file__).parent.parent.parent.parent / "res/images/circle_black.png").replace("\\", "/") PATH_TO_IMG2 = str(Path(__file__).parent.parent.parent.parent / "res/images/circle_blue.png").replace("\\", "/") class QtBoxStyleCheckBox4(QCheckBox): def __init__(self): super(QtBoxStyleCheckBox4, self).__init__(str(Path(__file__))) self.setText("Qt Box") self.setStyleSheet(""" QCheckBox { font-size: 15px; } QCheckBox:hover { color: rgba(0, 0, 0, 180); } QCheckBox::indicator { width: 20px; height: 20px; border: none; } QCheckBox::indicator:unchecked { image: url(%s); } QCheckBox::indicator:checked { image: url(%s); } """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PyQt # PySide # from PySide2.QtWidgets import QCheckBox # class QtBoxStyleCheckBox4(QCheckBox): # def __init__(self): # super(QtBoxStyleCheckBox4, self).__init__() # self.setText("Qt Box") # self.setStyleSheet(""" # QCheckBox { # font-size: 15px; # } # QCheckBox:hover { # color: rgba(0, 0, 0, 180); # } # QCheckBox::indicator { # width: 20px; # height: 20px; # border: none; # } # QCheckBox::indicator:unchecked { # image: url(%s); # } # QCheckBox::indicator:checked { # image: url(%s); # } # """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PySide # C++/Qt # #ifndef QTBOXSTYLECHECKBOX4_H # #define QTBOXSTYLECHECKBOX4_H # #include # class QtBoxStyleCheckBox4 : public QCheckBox # { # Q_OBJECT # public: # QtBoxStyleCheckBox4(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLECHECKBOX4_H # #include "qtboxstylecheckbox4.h" # QtBoxStyleCheckBox4::QtBoxStyleCheckBox4(QWidget *parent) # : QCheckBox(parent) # { # setText("Qt Box"); # setStyleSheet(R"( # QCheckBox { # font-size: 15px; # } # QCheckBox:hover { # color: rgba(0, 0, 0, 180); # } # QCheckBox::indicator { # width: 20px; # height: 20px; # border: none; # } # QCheckBox::indicator:unchecked { # image: url(PATH_TO_IMG); # } # QCheckBox::indicator:checked { # image: url(PATH_TO_IMG); # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/combobox/__init__.py ================================================ from .func import demo1, demo2 from .style import demo1, demo2, demo3 ================================================ FILE: src/qtbox/demo/combobox/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/combobox/func/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QComboBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QComboBox = createWidgetMenuBase(QComboBox) class QtBoxFuncComboBox1(QComboBox): def __init__(self): super(QtBoxFuncComboBox1, self).__init__(str(Path(__file__))) self.setEditable(True) self.addItems(['1', '2', '3', '4', '5', '6']) self.currentTextChanged.connect(self.update_item) def update_item(self, txt): self.setItemText(self.currentIndex(), txt) # PyQt # PySide # from PySide2.QtWidgets import QComboBox # class QtBoxFuncComboBox1(QComboBox): # def __init__(self): # super(QtBoxFuncComboBox1, self).__init__() # self.setEditable(True) # self.addItems(['1', '2', '3', '4', '5', '6']) # self.currentTextChanged.connect(self.update_item) # def update_item(self, txt): # self.setItemText(self.currentIndex(), txt) # PySide # C++/Qt # #ifndef QTBOXFUNCCOMBOBOX1_H # #define QTBOXFUNCCOMBOBOX1_H # #include # class QtBoxFuncComboBox1 : public QComboBox # { # Q_OBJECT # public: # QtBoxFuncComboBox1(QWidget *parent = nullptr); # private slots: # void updateItem(const QString &txt); # }; # #endif // QTBOXFUNCCOMBOBOX1_H # #include "qtboxfunccombobox1.h" # QtBoxFuncComboBox1::QtBoxFuncComboBox1(QWidget *parent) # : QComboBox(parent) # { # setEditable(true); # addItems({"1", "2", "3", "4", "5", "6"}); # connect(this, SIGNAL(currentTextChanged(const QString &)), this, SLOT(updateItem(const QString &))); # } # void QtBoxFuncComboBox1::updateItem(const QString &txt) # { # setItemText(currentIndex(), txt); # } # C++/Qt ================================================ FILE: src/qtbox/demo/combobox/func/demo2.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QComboBox, QCompleter from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QComboBox = createWidgetMenuBase(QComboBox) class QtBoxFuncComboBox2(QComboBox): def __init__(self): super(QtBoxFuncComboBox2, self).__init__(str(Path(__file__))) self.setEditable(True) self.addItems(['1', '2', '3', '4', '5', '6']) comp = QCompleter(["1a", "1b", "1c"]) comp.setFilterMode(Qt.MatchContains) self.setCompleter(comp) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QComboBox, QCompleter # class QtBoxFuncComboBox2(QComboBox): # def __init__(self): # super(QtBoxFuncComboBox2, self).__init__() # self.setEditable(True) # self.addItems(['1', '2', '3', '4', '5', '6']) # comp = QCompleter(["1a", "1b", "1c"]) # comp.setFilterMode(Qt.MatchContains) # self.setCompleter(comp) # PySide # C++/Qt # #ifndef QTBOXFUNCCOMBOBOX2_H # #define QTBOXFUNCCOMBOBOX2_H # #include # class QtBoxFuncComboBox2 : public QComboBox # { # Q_OBJECT # public: # QtBoxFuncComboBox2(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCCOMBOBOX2_H # #include "qtboxfunccombobox2.h" # #include # #include # QtBoxFuncComboBox2::QtBoxFuncComboBox2(QWidget *parent) # : QComboBox(parent) # { # setEditable(true); # addItems({"1", "2", "3", "4", "5", "6"}); # QCompleter *comp = new QCompleter({"1a", "1b", "1c"}); # comp->setFilterMode(Qt::MatchContains); # setCompleter(comp); # } # C++/Qt ================================================ FILE: src/qtbox/demo/combobox/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/combobox/style/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QComboBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QComboBox = createWidgetMenuBase(QComboBox) PATH_TO_IMG1 = str(Path(__file__).parent.parent.parent.parent / "res/images/down.png").replace("\\", "/") PATH_TO_IMG2 = str(Path(__file__).parent.parent.parent.parent / "res/images/up.png").replace("\\", "/") class QtBoxStyleComboBox1(QComboBox): def __init__(self): super(QtBoxStyleComboBox1, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.addItems(['1', '2', '3', '4', '5', '6']) self.setStyleSheet(""" QComboBox { background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #555555, stop:1 #313131); border: 1px solid lightgray; border-radius: 3px; font-weight: bold; color: white; padding-left: 15px; } QComboBox::drop-down { width: 22px; border-left: 1px solid darkgray; border-top-right-radius: 3px; border-bottom-right-radius: 3px; } QComboBox::down-arrow { width: 16px; height: 16px; image: url(%s); } QComboBox::down-arrow:on { image: url(%s); } QComboBox QAbstractItemView { color: white; border: none; outline: none; background-color: #313131; } QComboBox QScrollBar:vertical { width: 2px; background-color: white; } QComboBox QScrollBar::handle:vertical { background-color: #b2bdaf; } """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PyQt # PySide # from PySide2.QtWidgets import QComboBox # class QtBoxStyleComboBox1(QComboBox): # def __init__(self): # super(QtBoxStyleComboBox1, self).__init__() # self.setFixedSize(150, 30) # self.addItems(['1', '2', '3', '4', '5', '6']) # self.setStyleSheet(""" # QComboBox { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #555555, stop:1 #313131); # border: 1px solid lightgray; # border-radius: 3px; # font-weight: bold; # color: white; # padding-left: 15px; # } # QComboBox::drop-down { # width: 22px; # border-left: 1px solid darkgray; # border-top-right-radius: 3px; # border-bottom-right-radius: 3px; # } # QComboBox::down-arrow { # width: 16px; # height: 16px; # image: url(%s); # } # QComboBox::down-arrow:on { # image: url(%s); # } # QComboBox QAbstractItemView { # color: white; # border: none; # outline: none; # background-color: #313131; # } # QComboBox QScrollBar:vertical { # width: 2px; # background-color: white; # } # QComboBox QScrollBar::handle:vertical { # background-color: #b2bdaf; # } # """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PySide # C++/Qt # #ifndef QTBOXSTYLECOMBOBOX1_H # #define QTBOXSTYLECOMBOBOX1_H # #include # class QtBoxStyleComboBox1 : public QComboBox # { # Q_OBJECT # public: # QtBoxStyleComboBox1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLECOMBOBOX1_H # #include "qtboxstylecombobox1.h" # QtBoxStyleComboBox1::QtBoxStyleComboBox1(QWidget *parent) # : QComboBox(parent) # { # setFixedSize(150, 30); # addItems({"1", "2", "3", "4", "5", "6"}); # setStyleSheet(R"( # QComboBox { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #555555, stop:1 #313131); # border: 1px solid lightgray; # border-radius: 3px; # font-weight: bold; # color: white; # padding-left: 15px; # } # QComboBox::drop-down { # width: 22px; # border-left: 1px solid darkgray; # border-top-right-radius: 3px; # border-bottom-right-radius: 3px; # } # QComboBox::down-arrow { # width: 16px; # height: 16px; # image: url(PATH_TO_IMG); # } # QComboBox::down-arrow:on { # image: url(PATH_TO_IMG); # } # QComboBox QAbstractItemView { # color: white; # border: none; # outline: none; # background-color: #313131; # } # QComboBox QScrollBar:vertical { # width: 2px; # background-color: white; # } # QComboBox QScrollBar::handle:vertical { # background-color: #b2bdaf; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/combobox/style/demo2.py ================================================ # PyQt from PyQt5.QtWidgets import QComboBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QComboBox = createWidgetMenuBase(QComboBox) PATH_TO_IMG1 = str(Path(__file__).parent.parent.parent.parent / "res/images/down.png").replace("\\", "/") PATH_TO_IMG2 = str(Path(__file__).parent.parent.parent.parent / "res/images/up.png").replace("\\", "/") class QtBoxStyleComboBox2(QComboBox): def __init__(self): super(QtBoxStyleComboBox2, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.addItems(['1', '2', '3', '4', '5', '6']) self.setStyleSheet(""" QComboBox { background-color: white; color: black; border: 1px solid lightgray; border-radius: 15px; padding-left: 15px; } QComboBox:on { border: 1px solid #63acfb; } QComboBox::drop-down { width: 22px; border-left: 1px solid lightgray; border-top-right-radius: 15px; border-bottom-right-radius: 15px; } QComboBox::drop-down:on { border-left: 1px solid #63acfb; } QComboBox::down-arrow { width: 16px; height: 16px; image: url(%s); } QComboBox::down-arrow:on { image: url(%s); } QComboBox QAbstractItemView { color: black; border: none; outline: none; background-color: whitesmoke; } QComboBox QScrollBar:vertical { width: 2px; background-color: white; } QComboBox QScrollBar::handle:vertical { background-color: #b2bdaf; } """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PyQt # PySide # from PySide2.QtWidgets import QComboBox # class QtBoxStyleComboBox2(QComboBox): # def __init__(self): # super(QtBoxStyleComboBox2, self).__init__() # self.setFixedSize(150, 30) # self.addItems(['1', '2', '3', '4', '5', '6']) # self.setStyleSheet(""" # QComboBox { # background-color: white; # color: black; # border: 1px solid lightgray; # border-radius: 15px; # padding-left: 15px; # } # QComboBox:on { # border: 1px solid #63acfb; # } # QComboBox::drop-down { # width: 22px; # border-left: 1px solid lightgray; # border-top-right-radius: 15px; # border-bottom-right-radius: 15px; # } # QComboBox::drop-down:on { # border-left: 1px solid #63acfb; # } # QComboBox::down-arrow { # width: 16px; # height: 16px; # image: url(%s); # } # QComboBox::down-arrow:on { # image: url(%s); # } # QComboBox QAbstractItemView { # color: black; # border: none; # outline: none; # background-color: whitesmoke; # } # QComboBox QScrollBar:vertical { # width: 2px; # background-color: white; # } # QComboBox QScrollBar::handle:vertical { # background-color: #b2bdaf; # } # """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PySide # C++/Qt # #ifndef QTBOXSTYLECOMBOBOX2_H # #define QTBOXSTYLECOMBOBOX2_H # #include # class QtBoxStyleComboBox2 : public QComboBox # { # Q_OBJECT # public: # QtBoxStyleComboBox2(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLECOMBOBOX2_H # #include "qtboxstylecombobox2.h" # QtBoxStyleComboBox2::QtBoxStyleComboBox2(QWidget *parent) # : QComboBox(parent) # { # setFixedSize(150, 30); # addItems({"1", "2", "3", "4", "5", "6"}); # setStyleSheet(R"( # QComboBox { # background-color: white; # color: black; # border: 1px solid lightgray; # border-radius: 15px; # padding-left: 15px; # } # QComboBox:on { # border: 1px solid #63acfb; # } # QComboBox::drop-down { # width: 22px; # border-left: 1px solid lightgray; # border-top-right-radius: 15px; # border-bottom-right-radius: 15px; # } # QComboBox::drop-down:on { # border-left: 1px solid #63acfb; # } # QComboBox::down-arrow { # width: 16px; # height: 16px; # image: url(PATH_TO_IMG); # } # QComboBox::down-arrow:on { # image: url(PATH_TO_IMG); # } # QComboBox QAbstractItemView { # color: black; # border: none; # outline: none; # background-color: whitesmoke; # } # QComboBox QScrollBar:vertical { # width: 2px; # background-color: white; # } # QComboBox QScrollBar::handle:vertical { # background-color: #b2bdaf; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/combobox/style/demo3.py ================================================ # PyQt from PyQt5.QtWidgets import QComboBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QComboBox = createWidgetMenuBase(QComboBox) PATH_TO_IMG = str(Path(__file__).parent.parent.parent.parent / "res/images/up_down.png").replace("\\", "/") class QtBoxStyleComboBox3(QComboBox): def __init__(self): super(QtBoxStyleComboBox3, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.addItems(['1', '2', '3', '4', '5', '6']) self.setStyleSheet(""" QComboBox { background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #f5f5f7, stop:1 #dedee0); border: 1px solid whitesmoke; border-radius: 3px; padding-left: 15px; color: gray; } QComboBox::drop-down { width: 22px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; } QComboBox::down-arrow { width: 16px; height: 16px; image: url(%s); } QComboBox QAbstractItemView { color: gray; border: none; outline: none; background-color: #dedee0; } QComboBox QScrollBar:vertical { width: 2px; background-color: white; } QComboBox QScrollBar::handle:vertical { background-color: #b2bdaf; } """ % (PATH_TO_IMG)) # PyQt # PySide # from PySide2.QtWidgets import QComboBox # class QtBoxStyleComboBox3(QComboBox): # def __init__(self): # super(QtBoxStyleComboBox3, self).__init__() # self.setFixedSize(150, 30) # self.addItems(['1', '2', '3', '4', '5', '6']) # self.setStyleSheet(""" # QComboBox { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #f5f5f7, stop:1 #dedee0); # border: 1px solid whitesmoke; # border-radius: 3px; # padding-left: 15px; # color: gray; # } # QComboBox::drop-down { # width: 22px; # border-top-right-radius: 3px; # border-bottom-right-radius: 3px; # } # QComboBox::down-arrow { # width: 16px; # height: 16px; # image: url(%s); # } # QComboBox QAbstractItemView { # color: gray; # border: none; # outline: none; # background-color: #dedee0; # } # QComboBox QScrollBar:vertical { # width: 2px; # background-color: white; # } # QComboBox QScrollBar::handle:vertical { # background-color: #b2bdaf; # } # """ % (PATH_TO_IMG)) # PySide # C++/Qt # #ifndef QTBOXSTYLECOMBOBOX3_H # #define QTBOXSTYLECOMBOBOX3_H # #include # class QtBoxStyleComboBox3 : public QComboBox # { # Q_OBJECT # public: # QtBoxStyleComboBox3(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLECOMBOBOX3_H # #include "qtboxstylecombobox3.h" # QtBoxStyleComboBox3::QtBoxStyleComboBox3(QWidget *parent) # : QComboBox(parent) # { # setFixedSize(150, 30); # addItems({"1", "2", "3", "4", "5", "6"}); # setStyleSheet(R"( # QComboBox { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #f5f5f7, stop:1 #dedee0); # border: 1px solid whitesmoke; # border-radius: 3px; # padding-left: 15px; # color: gray; # } # QComboBox::drop-down { # width: 22px; # border-top-right-radius: 3px; # border-bottom-right-radius: 3px; # } # QComboBox::down-arrow { # width: 16px; # height: 16px; # image: url(PATH_TO_IMG); # } # QComboBox QAbstractItemView { # color: gray; # border: none; # outline: none; # background-color: #dedee0; # } # QComboBox QScrollBar:vertical { # width: 2px; # background-color: white; # } # QComboBox QScrollBar::handle:vertical { # background-color: #b2bdaf; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/dial/__init__.py ================================================ from .func import demo1 from .style import demo1, demo2 ================================================ FILE: src/qtbox/demo/dial/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/dial/func/demo1.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtGui import QPainter, QFont, QFontMetricsF from PyQt5.QtWidgets import QDial from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QDial = createWidgetMenuBase(QDial) class QtBoxFuncDial1(QDial): def __init__(self): super(QtBoxFuncDial1, self).__init__(str(Path(__file__))) self.setRange(0, 100) self.setWrapping(True) self.setNotchTarget(10) self.setNotchesVisible(True) def paintEvent(self, event): super(QtBoxFuncDial1, self).paintEvent(event) painter = QPainter(self) font = QFont() font.setPixelSize(18) painter.setFont(font) font_metrics = QFontMetricsF(font) text_width = font_metrics.width(str(self.value())) painter.drawText(int(self.width()/2-text_width/2), int(self.height()/2), str(self.value())) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtGui import QPainter, QFont, QFontMetricsF # from PySide2.QtWidgets import QDial # class QtBoxFuncDial1(QDial): # def __init__(self): # super(QtBoxFuncDial1, self).__init__(str(Path(__file__))) # self.setRange(0, 100) # self.setWrapping(True) # self.setNotchTarget(10) # self.setNotchesVisible(True) # def paintEvent(self, event): # super(QtBoxFuncDial1, self).paintEvent(event) # painter = QPainter(self) # font = QFont() # font.setPixelSize(18) # painter.setFont(font) # font_metrics = QFontMetricsF(font) # text_width = font_metrics.width(str(self.value())) # painter.drawText(int(self.width()/2-text_width/2), int(self.height()/2), str(self.value())) # PySide # C++/Qt # #ifndef QTBOXFUNCDIAL1_H # #define QTBOXFUNCDIAL1_H # #include # class QtBoxFuncDial1 : public QDial # { # Q_OBJECT # public: # QtBoxFuncDial1(QWidget *parent = nullptr); # protected: # void paintEvent(QPaintEvent *event); # }; # #endif // QTBOXFUNCDIAL1_H # #include "qtboxfuncdial1.h" # #include # #include # #include # #include # #include # QtBoxFuncDial1::QtBoxFuncDial1(QWidget *parent) # : QDial(parent) # { # setRange(0, 100); # setWrapping(true); # setNotchTarget(10); # setNotchesVisible(true); # } # void QtBoxFuncDial1::paintEvent(QPaintEvent *event) # { # QDial::paintEvent(event); # QPainter painter(this); # QFont font = QFont(); # font.setPixelSize(18); # painter.setFont(font); # QFontMetricsF fontMetrics = QFontMetricsF(font); # float textWidth = fontMetrics.size(Qt::TextSingleLine, QString("%1").arg(value())).width(); # painter.drawText(int(this->width()/2-textWidth/2), int(this->height()/2), QString("%1").arg(value())); # } # C++/Qt ================================================ FILE: src/qtbox/demo/dial/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/dial/style/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QDial from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QDial = createWidgetMenuBase(QDial) class QtBoxStyleDial1(QDial): def __init__(self): super(QtBoxStyleDial1, self).__init__(str(Path(__file__))) self.setStyleSheet(""" QDial { background-color: gray; } """) # PyQt # PySide # from PySide2.QtWidgets import QDial # class QtBoxStyleDial1(QDial): # def __init__(self): # super(QtBoxStyleDial1, self).__init__(str(Path(__file__))) # self.setStyleSheet(""" # QDial { # background-color: gray; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEDIAL1_H # #define QTBOXSTYLEDIAL1_H # #include # class QtBoxStyleDial1 : public QDial # { # Q_OBJECT # public: # QtBoxStyleDial1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEDIAL1_H # #include "qtboxstyledial1.h" # QtBoxStyleDial1::QtBoxStyleDial1(QWidget *parent) # : QDial(parent) # { # setStyleSheet("QDial {background-color: gray}"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/dial/style/demo2.py ================================================ # PyQt from PyQt5.QtGui import QPainter, QColor, QLinearGradient, QFont, QFontMetricsF, QPen from PyQt5.QtCore import Qt, QPointF from PyQt5.QtWidgets import QDial from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path import math QDial = createWidgetMenuBase(QDial) class QtBoxStyleDial2(QDial): def __init__(self): super(QtBoxStyleDial2, self).__init__(str(Path(__file__))) self.setFixedSize(100, 100) self.setRange(100, 200) self.setWrapping(True) self.mouse_x = 0 self.mouse_y = 0 self.is_first_paint = True def mousePressEvent(self, event): super(QtBoxStyleDial2, self).mousePressEvent(event) if event.button() == Qt.LeftButton: self.mouse_x = event.x() self.mouse_y = event.y() def mouseMoveEvent(self, event): super(QtBoxStyleDial2, self).mouseMoveEvent(event) if event.buttons() == Qt.LeftButton: self.mouse_x = event.x() self.mouse_y = event.y() def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) pen = QPen() pen.setColor(Qt.lightGray) painter.setPen(pen) linear_gradient = QLinearGradient(self.rect().topLeft(), self.rect().bottomRight()) linear_gradient.setColorAt(0, QColor(Qt.white)) linear_gradient.setColorAt(1, QColor(Qt.black)) painter.setBrush(linear_gradient) painter.drawEllipse(self.rect()) if self.is_first_paint: self.mouse_x = self.rect().center().x() self.mouse_y = self.rect().bottom() self.is_first_paint = False handle_radius = 10 painter.setBrush(Qt.white) handle_x, handle_y = self.get_handle_pos() painter.drawEllipse(QPointF(handle_x, handle_y), handle_radius, handle_radius) angle = self.get_angle([handle_x, handle_y]) self.setValue(round(angle / 360 * (self.maximum() - self.minimum())) + self.minimum()) font = QFont() font.setPixelSize(18) painter.setFont(font) font_metrics = QFontMetricsF(font) text_width = font_metrics.width(str(self.value())) painter.drawText(int(self.width() / 2 - text_width / 2), int(self.height() / 2), str(self.value())) def get_handle_pos(self): center_x = self.rect().center().x() center_y = self.rect().center().y() if self.mouse_x - center_x == 0 and self.mouse_y - center_y == 0: diff_x = center_x diff_y = center_y else: diff_x = self.mouse_x - center_x diff_y = self.mouse_y - center_y pos_adjust_value = 1.5 length = math.sqrt(diff_x ** 2 + diff_y ** 2) ratio = length / (self.rect().width() / 2) * pos_adjust_value handle_x = diff_x / ratio + center_x handle_y = diff_y / ratio + center_y return handle_x, handle_y def get_angle(self, handle_pos): """get the angle between handle and the start pos""" center_x = self.rect().center().x() center_y = self.rect().center().y() start_pos = [self.rect().center().x(), self.rect().bottom()] vx1 = start_pos[0] - center_x vy1 = start_pos[1] - center_y vx2 = handle_pos[0] - center_x vy2 = handle_pos[1] - center_y angle1 = math.atan2(vy1, vx1) angle1 = angle1 * 180 / math.pi angle2 = math.atan2(vy2, vx2) angle2 = angle2 * 180 / math.pi if angle2 >= 0: diff_angle = angle2 - angle1 if diff_angle < 0: diff_angle = 360 - abs(diff_angle) else: diff_angle = 180 + angle2 + angle1 return diff_angle # PyQt # PySide # from PySide2.QtGui import QPainter, QColor, QLinearGradient, QFont, QFontMetricsF, QPen # from PySide2.QtCore import Qt, QPointF # from PySide2.QtWidgets import QDial # import math # class QtBoxStyleDial2(QDial): # def __init__(self): # super(QtBoxStyleDial2, self).__init__(str(Path(__file__))) # self.setFixedSize(100, 100) # self.setRange(100, 200) # self.setWrapping(True) # self.mouse_x = 0 # self.mouse_y = 0 # self.is_first_paint = True # def mousePressEvent(self, event): # super(QtBoxStyleDial2, self).mousePressEvent(event) # if event.button() == Qt.LeftButton: # self.mouse_x = event.x() # self.mouse_y = event.y() # def mouseMoveEvent(self, event): # super(QtBoxStyleDial2, self).mouseMoveEvent(event) # if event.buttons() == Qt.LeftButton: # self.mouse_x = event.x() # self.mouse_y = event.y() # def paintEvent(self, event): # painter = QPainter(self) # painter.setRenderHint(QPainter.Antialiasing) # pen = QPen() # pen.setColor(Qt.lightGray) # painter.setPen(pen) # linear_gradient = QLinearGradient(self.rect().topLeft(), self.rect().bottomRight()) # linear_gradient.setColorAt(0, QColor(Qt.white)) # linear_gradient.setColorAt(1, QColor(Qt.black)) # painter.setBrush(linear_gradient) # painter.drawEllipse(self.rect()) # if self.is_first_paint: # self.mouse_x = self.rect().center().x() # self.mouse_y = self.rect().bottom() # self.is_first_paint = False # handle_radius = 10 # painter.setBrush(Qt.white) # handle_x, handle_y = self.get_handle_pos() # painter.drawEllipse(QPointF(handle_x, handle_y), handle_radius, handle_radius) # angle = self.get_angle([handle_x, handle_y]) # self.setValue(round(angle / 360 * (self.maximum() - self.minimum())) + self.minimum()) # font = QFont() # font.setPixelSize(18) # painter.setFont(font) # font_metrics = QFontMetricsF(font) # text_width = font_metrics.width(str(self.value())) # painter.drawText(int(self.width() / 2 - text_width / 2), int(self.height() / 2), str(self.value())) # def get_handle_pos(self): # center_x = self.rect().center().x() # center_y = self.rect().center().y() # if self.mouse_x - center_x == 0 and self.mouse_y - center_y == 0: # diff_x = center_x # diff_y = center_y # else: # diff_x = self.mouse_x - center_x # diff_y = self.mouse_y - center_y # pos_adjust_value = 1.5 # length = math.sqrt(diff_x ** 2 + diff_y ** 2) # ratio = length / (self.rect().width() / 2) * pos_adjust_value # handle_x = diff_x / ratio + center_x # handle_y = diff_y / ratio + center_y # return handle_x, handle_y # def get_angle(self, handle_pos): # """get the angle between handle and the start pos""" # center_x = self.rect().center().x() # center_y = self.rect().center().y() # start_pos = [self.rect().center().x(), self.rect().bottom()] # vx1 = start_pos[0] - center_x # vy1 = start_pos[1] - center_y # vx2 = handle_pos[0] - center_x # vy2 = handle_pos[1] - center_y # angle1 = math.atan2(vy1, vx1) # angle1 = angle1 * 180 / math.pi # angle2 = math.atan2(vy2, vx2) # angle2 = angle2 * 180 / math.pi # if angle2 >= 0: # diff_angle = angle2 - angle1 # if diff_angle < 0: # diff_angle = 360 - abs(diff_angle) # else: # diff_angle = 180 + angle2 + angle1 # return diff_angle # PySide # C++/Qt # #ifndef QTBOXSTYLEDIAL2_H # #define QTBOXSTYLEDIAL2_H # #include # class QtBoxStyleDial2 : public QDial # { # Q_OBJECT # public: # QtBoxStyleDial2(QWidget *parent = nullptr); # protected: # void mousePressEvent(QMouseEvent *event); # void mouseMoveEvent(QMouseEvent *event); # void paintEvent(QPaintEvent *event); # private: # int mouseX = 0; # int mouseY = 0; # bool isFirstPaint = true; # float* getHandlePos(); # float getAngle(float *handlePos); # }; # #endif // QTBOXSTYLEDIAL2_H # #include "qtboxstyledial2.h" # #include # #include # #include # #include # #include # #include # #include # #include # #include # #include # QtBoxStyleDial2::QtBoxStyleDial2(QWidget *parent) # : QDial(parent) # { # setFixedSize(100, 100); # setRange(100, 200); # setWrapping(true); # } # void QtBoxStyleDial2::mousePressEvent(QMouseEvent *event) # { # QDial::mousePressEvent(event); # if (event->button() == Qt::LeftButton) { # mouseX = event->x(); # mouseY = event->y(); # } # } # # void QtBoxStyleDial2::mouseMoveEvent(QMouseEvent *event) # { # QDial::mouseMoveEvent(event); # if (event->buttons() == Qt::LeftButton) { # mouseX = event->x(); # mouseY = event->y(); # } # } # void QtBoxStyleDial2::paintEvent(QPaintEvent *event) # { # QPainter painter(this); # painter.setRenderHint(QPainter::Antialiasing); # QPen pen = QPen(); # pen.setColor(Qt::lightGray); # painter.setPen(pen); # QLinearGradient linearGradient = QLinearGradient(rect().topLeft(), rect().bottomRight()); # linearGradient.setColorAt(0, QColor(Qt::white)); # linearGradient.setColorAt(1, QColor(Qt::black)); # painter.setBrush(linearGradient); # painter.drawEllipse(rect()); # if (isFirstPaint) { # mouseX = rect().center().x(); # mouseY = rect().bottom(); # isFirstPaint = false; # } # int handleRadius = 10; # painter.setBrush(Qt::white); # float *handlePos = getHandlePos(); # float handleX = handlePos[0]; # float handleY = handlePos[1]; # painter.drawEllipse(QPointF(handleX, handleY), handleRadius, handleRadius); # float angle = getAngle(handlePos); # setValue(round(angle / 360 * (maximum()-minimum())) + minimum()); # delete[] handlePos; # QFont font = QFont(); # font.setPixelSize(18); # painter.setFont(font); # QFontMetricsF fontMetrics = QFontMetrics(font); # float textWidth = fontMetrics.size(Qt::TextSingleLine, QString("%1").arg(value())).width(); # painter.drawText(int(width()/2-textWidth/2), int(height()/2), QString("%1").arg(value())); # } # float* QtBoxStyleDial2::getHandlePos() # { # int centerX = rect().center().x(); # int centerY = rect().center().y(); # int diffX; # int diffY; # if (mouseX-centerX == 0 && mouseY-centerY == 0) { # diffX = centerX; # diffY = centerY; # } # else { # diffX = mouseX - centerX; # diffY = mouseY - centerY; # } # float posAdjustValue = 1.5; # float length = sqrt(pow(diffX, 2) + pow(diffY, 2)); # float ratio = length / (rect().width()/2) * posAdjustValue; # float handleX = diffX / ratio + centerX; # float handleY = diffY / ratio + centerY; # float *result = new float[2]; # result[0] = handleX; # result[1] = handleY; # return result; # } # float QtBoxStyleDial2::getAngle(float *handlePos) # { # int centerX = rect().center().x(); # int centerY = rect().center().y(); # int startPos[2] = {rect().center().x(), rect().bottom()}; # float vx1 = startPos[0] - centerX; # float vy1 = startPos[1] - centerY; # float vx2 = handlePos[0] - centerX; # float vy2 = handlePos[1] - centerY; # float angle1 = atan2(vy1, vx1); # angle1 = angle1 * 180 / M_PI; # float angle2 = atan2(vy2, vx2); # angle2 = angle2 * 180 / M_PI; # float diffAngle; # if (angle2 >= 0) { # diffAngle = angle2 - angle1; # if (diffAngle < 0) { # diffAngle = 360 - abs(diffAngle); # } # } # else { # diffAngle = 180 + angle2 + angle1; # } # return diffAngle; # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/__init__.py ================================================ from .func import demo1, demo2, demo3, demo4, demo5, demo6, demo7 from .style import demo1, demo2, demo3, demo4 ================================================ FILE: src/qtbox/demo/label/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/label/func/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) class QtBoxFuncLabel1(QLabel): def __init__(self): super(QtBoxFuncLabel1, self).__init__(str(Path(__file__))) self.setText("Qt Box link") self.setOpenExternalLinks(True) # PyQt # PySide # from PySide2.QtWidgets import QLabel # class QtBoxFuncLabel1(QLabel): # def __init__(self): # super(QtBoxFuncLabel1, self).__init__() # self.setText("Qt Box link") # self.setOpenExternalLinks(True) # PySide # C++/Qt # #ifndef QTBOXFUNCLABEL1_H # #define QTBOXFUNCLABEL1_H # #include # class QtBoxFuncLabel1 : public QLabel # { # Q_OBJECT # public: # QtBoxFuncLabel1(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCLABEL1_H # #include "qtboxfunclabel1.h" # QtBoxFuncLabel1::QtBoxFuncLabel1(QWidget *parent) # : QLabel(parent) # { # setText("Qt Box link"); # setOpenExternalLinks(true); # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/func/demo2.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) class QtBoxFuncLabel2(QLabel): def __init__(self): super(QtBoxFuncLabel2, self).__init__(str(Path(__file__))) self.setText("I'm editable.") self.setTextInteractionFlags(Qt.TextEditorInteraction) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QLabel # class QtBoxFuncLabel2(QLabel): # def __init__(self): # super(QtBoxFuncLabel2, self).__init__() # self.setText("I'm editable.") # self.setTextInteractionFlags(Qt.TextEditorInteraction) # PySide # C++/Qt # #ifndef QTBOXFUNCLABEL2_H # #define QTBOXFUNCLABEL2_H # #include # class QtBoxFuncLabel2 : public QLabel # { # Q_OBJECT # public: # QtBoxFuncLabel2(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCLABEL2_H # #include "qtboxfunclabel2.h" # #include # QtBoxFuncLabel2::QtBoxFuncLabel2(QWidget *parent) # : QLabel(parent) # { # setText("I'm editable."); # setTextInteractionFlags(Qt::TextEditorInteraction); # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/func/demo3.py ================================================ # PyQt from PyQt5.QtCore import QTimer from PyQt5.QtWidgets import QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) class QtBoxFuncLabel3(QLabel): def __init__(self): super(QtBoxFuncLabel3, self).__init__(str(Path(__file__))) self.text = "" self.count = 0 self.timer = QTimer() self.timer.timeout.connect(self.update_text) self.type_text("Typewriter effect") def type_text(self, txt): self.text = txt self.count = 0 self.timer.stop() self.timer.start(500) def update_text(self): self.count += 1 self.setText(self.text[0:self.count]) if self.count >= len(self.text): self.count = 0 self.timer.stop() # PyQt # PySide # from PySide2.QtCore import QTimer # from PySide2.QtWidgets import QLabel # class QtBoxFuncLabel3(QLabel): # def __init__(self): # super(QtBoxFuncLabel3, self).__init__() # self.text = "" # self.count = 0 # self.timer = QTimer() # self.timer.timeout.connect(self.update_text) # self.type_text("Typewriter effect") # def type_text(self, txt): # self.text = txt # self.count = 0 # self.timer.stop() # self.timer.start(500) # def update_text(self): # self.count += 1 # self.setText(self.text[0:self.count]) # # if self.count >= len(self.text): # self.count = 0 # self.timer.stop() # PySide # C++/Qt # #ifndef QTBOXFUNCLABEL3_H # #define QTBOXFUNCLABEL3_H # #include # #include # #include # class QtBoxFuncLabel3 : public QLabel # { # Q_OBJECT # public: # QtBoxFuncLabel3(QWidget *parent = nullptr); # private: # QString text = ""; # int count = 0; # QTimer *timer = new QTimer(); # void typeText(const QString &txt); # private slots: # void updateText(); # }; # #endif // QTBOXFUNCLABEL3_H # #include "qtboxfunclabel3.h" # QtBoxFuncLabel3::QtBoxFuncLabel3(QWidget *parent) # : QLabel(parent) # { # connect(timer, SIGNAL(timeout()), this, SLOT(updateText())); # typeText("Typewriter effect"); # } # void QtBoxFuncLabel3::typeText(const QString &txt) # { # text = txt; # count = 0; # timer->stop(); # timer->start(500); # } # void QtBoxFuncLabel3::updateText() # { # count += 1; # setText(text.left(count)); # if (count >= text.length()) { # count = 0; # timer->stop(); # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/func/demo4.py ================================================ # PyQt from PyQt5.QtGui import QMovie from PyQt5.QtWidgets import QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) PATH_TO_GIF = str(Path(__file__).parent.parent.parent.parent / "res/images/exercise.gif").replace("\\", "/") class QtBoxFuncLabel4(QLabel): def __init__(self): super(QtBoxFuncLabel4, self).__init__(str(Path(__file__))) movie = QMovie() movie.setFileName(PATH_TO_GIF) self.setMovie(movie) movie.start() # PyQt # PySide # from PySide2.QtGui import QMovie # from PySide2.QtWidgets import QLabel # class QtBoxFuncLabel4(QLabel): # def __init__(self): # super(QtBoxFuncLabel4, self).__init__(str(Path(__file__))) # movie = QMovie() # movie.setFileName(PATH_TO_GIF) # self.setMovie(movie) # movie.start() # PySide # C++/Qt # #ifndef QTBOXFUNCLABEL4_H # #define QTBOXFUNCLABEL4_H # #include # #include # class QtBoxFuncLabel4 : public QLabel # { # Q_OBJECT # public: # QtBoxFuncLabel4(QWidget *parent = nullptr); # private: # QMovie *movie = new QMovie(); # }; # #endif // QTBOXFUNCLABEL4_H # #include "qtboxfunclabel4.h" # QtBoxFuncLabel4::QtBoxFuncLabel4(QWidget *parent) # : QLabel(parent) # { # movie->setFileName(PATH_TO_GIF); # setMovie(movie); # movie->start(); # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/func/demo5.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) class QtBoxFuncLabel5(QLabel): def __init__(self): super(QtBoxFuncLabel5, self).__init__(str(Path(__file__))) text = 'Lay words vertically'.replace(" ", "\n") self.setText(text) self.setAlignment(Qt.AlignCenter) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QLabel # class QtBoxFuncLabel5(QLabel): # def __init__(self): # super(QtBoxFuncLabel5, self).__init__(str(Path(__file__))) # text = 'Lay words vertically'.replace(" ", "\n") # self.setText(text) # self.setAlignment(Qt.AlignCenter) # PySide # C++/Qt # #ifndef QTBOXFUNCLABEL5_H # #define QTBOXFUNCLABEL5_H # #include # class QtBoxFuncLabel5 : public QLabel # { # Q_OBJECT # public: # QtBoxFuncLabel5(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCLABEL5_H # #include "qtboxfunclabel5.h" # #include # #include # QtBoxFuncLabel5::QtBoxFuncLabel5(QWidget *parent) # : QLabel(parent) # { # QString text = "Lay words vertically"; # text = text.replace(" ", "\n"); # setText(text); # setAlignment(Qt::AlignCenter); # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/func/demo6.py ================================================ # PyQt from PyQt5.QtCore import QTimer, QTime from PyQt5.QtWidgets import QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) class QtBoxFuncLabel6(QLabel): def __init__(self): super(QtBoxFuncLabel6, self).__init__(str(Path(__file__))) self.update_text() self.timer = QTimer() self.timer.timeout.connect(self.update_text) self.timer.start(1000) def update_text(self): self.setText(QTime.currentTime().toString()) # PyQt # PySide # from PySide2.QtCore import QTimer, QTime # from PySide2.QtWidgets import QLabel # class QtBoxFuncLabel6(QLabel): # def __init__(self): # super(QtBoxFuncLabel6, self).__init__(str(Path(__file__))) # self.update_text() # self.timer = QTimer() # self.timer.timeout.connect(self.update_text) # self.timer.start(1000) # def update_text(self): # self.setText(QTime.currentTime().toString()) # PySide # C++/Qt # #ifndef QTBOXFUNCLABEL6_H # #define QTBOXFUNCLABEL6_H # #include # #include # class QtBoxFuncLabel6 : public QLabel # { # Q_OBJECT # public: # QtBoxFuncLabel6(QWidget *parent = nullptr); # private: # QTimer *timer = new QTimer(); # # private slots: # void updateText(); # }; # #endif // QTBOXFUNCLABEL6_H # #include "qtboxfunclabel6.h" # #include # QtBoxFuncLabel6::QtBoxFuncLabel6(QWidget *parent) # : QLabel(parent) # { # updateText(); # connect(timer, SIGNAL(timeout()), this, SLOT(updateText())); # timer->start(1000); # } # void QtBoxFuncLabel6::updateText() # { # setText(QTime::currentTime().toString()); # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/func/demo7.py ================================================ # PyQt from PyQt5.QtWidgets import QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) class QtBoxFuncLabel7(QLabel): def __init__(self): super(QtBoxFuncLabel7, self).__init__(str(Path(__file__))) self.setText("Drop a txt file on me.\n" "I will show its content.") self.setAcceptDrops(True) def dragEnterEvent(self, event): super(QtBoxFuncLabel7, self).dragEnterEvent(event) if event.mimeData().hasUrls(): event.acceptProposedAction() def dropEvent(self, event): super(QtBoxFuncLabel7, self).dropEvent(event) url = event.mimeData().urls()[0].toLocalFile() if not url.endswith(".txt"): return with open(url, "r", encoding="utf-8") as f: self.setText(f.read()) # PyQt # PySide # from PySide2.QtWidgets import QLabel # class QtBoxFuncLabel7(QLabel): # def __init__(self): # super(QtBoxFuncLabel7, self).__init__() # self.setText("Drop a txt file on me.\n" # "I will show its content.") # self.setAcceptDrops(True) # def dragEnterEvent(self, event): # super(QtBoxFuncLabel7, self).dragEnterEvent(event) # if event.mimeData().hasUrls(): # event.acceptProposedAction() # def dropEvent(self, event): # super(QtBoxFuncLabel7, self).dropEvent(event) # url = event.mimeData().urls()[0].toLocalFile() # if not url.endswith(".txt"): # return # with open(url, "r", encoding="utf-8") as f: # self.setText(f.read()) # PySide # C++/Qt # #ifndef QTBOXFUNCLABEL7_H # #define QTBOXFUNCLABEL7_H # #include # #include # #include # class QtBoxFuncLabel7 : public QLabel # { # Q_OBJECT # public: # QtBoxFuncLabel7(QWidget *parent = nullptr); # protected: # void dragEnterEvent(QDragEnterEvent *event); # void dropEvent(QDropEvent *event); # }; # #endif // QTBOXFUNCLABEL7_H # #include "qtboxfunclabel7.h" # #include # #include # #include # #include # QtBoxFuncLabel7::QtBoxFuncLabel7(QWidget *parent) # : QLabel(parent) # { # setText("Drop a txt file on me.\n" # "I will show its content."); # setAcceptDrops(true); # } # void QtBoxFuncLabel7::dragEnterEvent(QDragEnterEvent *event) # { # QLabel::dragEnterEvent(event); # if (event->mimeData()->hasUrls()) { # event->acceptProposedAction(); # } # } # void QtBoxFuncLabel7::dropEvent(QDropEvent *event) # { # QLabel::dropEvent(event); # QString url = event->mimeData()->urls()[0].toLocalFile(); # if (!url.endsWith(".txt")) { # return; # } # QFile file(url); # file.open(QIODevice::ReadOnly); # setText(file.readAll()); # file.close(); # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/label/style/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) PATH_TO_IMG = str(Path(__file__).parent.parent.parent.parent / "res/images/qt.png").replace("\\", "/") class QtBoxStyleLabel1(QLabel): def __init__(self): super(QtBoxStyleLabel1, self).__init__(str(Path(__file__))) self.setFixedSize(90, 90) self.setStyleSheet(""" QLabel { border-radius: 45px; border-image: url(%s) } """ % (PATH_TO_IMG)) # PyQt # PySide # from PySide2.QtWidgets import QLabel # class QtBoxStyleLabel1(QLabel): # def __init__(self): # super(QtBoxStyleLabel1, self).__init__() # self.setFixedSize(90, 90) # self.setStyleSheet(""" # QLabel { # border-radius: 45px; # border-image: url(%s) # } # """ % (PATH_TO_IMG)) # PySide # C++/Qt # #ifndef QTBOXSTYLELABEL1_H # #define QTBOXSTYLELABEL1_H # #include # class QtBoxStyleLabel1 : public QLabel # { # Q_OBJECT # public: # QtBoxStyleLabel1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLELABEL1_H # #include "qtboxstylelabel1.h" # QtBoxStyleLabel1::QtBoxStyleLabel1(QWidget *parent) # : QLabel(parent) # { # setFixedSize(90, 90); # setStyleSheet(R"( # QLabel { # border-radius: 45px; # border-image: url(:res/images/qt.png) # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/style/demo2.py ================================================ # PyQt from PyQt5.QtWidgets import QLabel from PyQt5.QtCore import Qt, QPointF from PyQt5.QtGui import QPixmap, QPainter, QBrush from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) PATH_TO_IMG = str(Path(__file__).parent.parent.parent.parent / "res/images/qt.png").replace("\\", "/") class QtBoxStyleLabel2(QLabel): def __init__(self): super(QtBoxStyleLabel2, self).__init__(str(Path(__file__))) self.setFixedSize(90, 90) self.pixmap = QPixmap(PATH_TO_IMG).scaled(self.width(), self.height()) def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.setPen(Qt.NoPen) brush = QBrush(self.pixmap) painter.setBrush(brush) points = [ QPointF(10.0, 80.0), QPointF(20.0, 10.0), QPointF(80.0, 30.0), QPointF(90.0, 70.0) ] painter.drawConvexPolygon(*points) # PyQt # PySide # from PySide2.QtWidgets import QLabel # from PySide2.QtCore import Qt, QPointF # from PySide2.QtGui import QPixmap, QPainter, QBrush # class QtBoxStyleLabel2(QLabel): # def __init__(self): # super(QtBoxStyleLabel2, self).__init__() # self.setFixedSize(90, 90) # self.pixmap = QPixmap(PATH_TO_IMG).scaled(self.width(), self.height()) # def paintEvent(self, event): # painter = QPainter(self) # painter.setRenderHint(QPainter.Antialiasing) # painter.setPen(Qt.NoPen) # brush = QBrush(self.pixmap) # painter.setBrush(brush) # points = [ # QPointF(10.0, 80.0), # QPointF(20.0, 10.0), # QPointF(80.0, 30.0), # QPointF(90.0, 70.0) # ] # painter.drawConvexPolygon(points) # PySide # C++/Qt # #ifndef QTBOXSTYLELABEL2_H # #define QTBOXSTYLELABEL2_H # #include # #include # #include # class QtBoxStyleLabel2 : public QLabel # { # Q_OBJECT # public: # QtBoxStyleLabel2(QWidget *parent = nullptr); # protected: # void paintEvent(QPaintEvent *event); # private: # QPixmap pixmap; # }; # #endif // QTBOXSTYLELABEL2_H # #include "qtboxstylelabel2.h" # #include # #include # #include # #include # QtBoxStyleLabel2::QtBoxStyleLabel2(QWidget *parent) # : QLabel(parent) # { # setFixedSize(90, 90); # pixmap = QPixmap(":res/images/qt.png").scaled(width(), height()); # } # void QtBoxStyleLabel2::paintEvent(QPaintEvent *event) # { # QPainter painter(this); # painter.setRenderHint(QPainter::Antialiasing); # painter.setPen(Qt::NoPen); # QBrush brush = QBrush(pixmap); # painter.setBrush(brush); # QPointF points[4] = { # QPointF(10.0, 80.0), # QPointF(20.0, 10.0), # QPointF(80.0, 30.0), # QPointF(90.0, 70.0) # }; # painter.drawPolygon(points, 4); # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/style/demo3.py ================================================ # PyQt from PyQt5.QtWidgets import QLabel, QGraphicsBlurEffect from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) class QtBoxStyleLabel3(QLabel): def __init__(self): super(QtBoxStyleLabel3, self).__init__(str(Path(__file__))) self.setText("Blur") self.blur() def blur(self): blur = QGraphicsBlurEffect(self) blur.setBlurRadius(6) blur.setBlurHints(QGraphicsBlurEffect.QualityHint) self.setGraphicsEffect(blur) # PyQt # PySide # from PySide2.QtWidgets import QLabel, QGraphicsBlurEffect # class QtBoxStyleLabel3(QLabel): # def __init__(self): # super(QtBoxStyleLabel3, self).__init__() # self.setText("Blur") # self.blur() # def blur(self): # blur = QGraphicsBlurEffect(self) # blur.setBlurRadius(6) # blur.setBlurHints(QGraphicsBlurEffect.QualityHint) # self.setGraphicsEffect(blur) # PySide # C++/Qt # #ifndef QTBOXSTYLELABEL3_H # #define QTBOXSTYLELABEL3_H # #include # class QtBoxStyleLabel3 : public QLabel # { # Q_OBJECT # public: # QtBoxStyleLabel3(QWidget *parent = nullptr); # private: # void blur(); # }; # #endif // QTBOXSTYLELABEL3_H # #include "qtboxstylelabel3.h" # #include # QtBoxStyleLabel3::QtBoxStyleLabel3(QWidget *parent) # : QLabel(parent) # { # setText("Blur"); # blur(); # } # void QtBoxStyleLabel3::blur() { # QGraphicsBlurEffect *blur = new QGraphicsBlurEffect(this); # blur->setBlurRadius(2); # blur->setBlurHints(QGraphicsBlurEffect::QualityHint); # setGraphicsEffect(blur); # } # C++/Qt ================================================ FILE: src/qtbox/demo/label/style/demo4.py ================================================ # PyQt from PyQt5.QtCore import QTimer from PyQt5.QtWidgets import QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLabel = createWidgetMenuBase(QLabel) class QtBoxStyleLabel4(QLabel): def __init__(self): super(QtBoxStyleLabel4, self).__init__(str(Path(__file__))) self.setText("Change text color") self.color_list = ["rgb(255, 0, 0)", "rgb(255, 165, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)", "rgb(0, 127, 255)", "rgb(0, 0, 255)", "rgb(139, 0, 255)"] self.count = 0 self.timer = QTimer() self.timer.timeout.connect(self.change_color) self.timer.start(100) def change_color(self): color = self.color_list[self.count] self.setStyleSheet(f""" color: {color} """) self.count += 1 if self.count >= len(self.color_list): self.count = 0 # PyQt # PySide # from PySide2.QtCore import QTimer # from PySide2.QtWidgets import QLabel # class QtBoxStyleLabel4(QLabel): # def __init__(self): # super(QtBoxStyleLabel4, self).__init__() # self.setText("Change text color") # self.color_list = ["rgb(255, 0, 0)", "rgb(255, 165, 0)", "rgb(255, 255, 0)", # "rgb(0, 255, 0)", "rgb(0, 127, 255)", "rgb(0, 0, 255)", # "rgb(139, 0, 255)"] # self.count = 0 # self.timer = QTimer() # self.timer.timeout.connect(self.change_color) # self.timer.start(100) # def change_color(self): # color = self.color_list[self.count] # self.setStyleSheet(f""" # color: {color} # """) # self.count += 1 # if self.count >= len(self.color_list): # self.count = 0 # PySide # C++/Qt # #ifndef QTBOXSTYLELABEL4_H # #define QTBOXSTYLELABEL4_H # #include # #include # #include # class QtBoxStyleLabel4 : public QLabel # { # Q_OBJECT # public: # QtBoxStyleLabel4(QWidget *parent = nullptr); # private: # unsigned int count = 0; # QTimer *timer = new QTimer(); # QString colorList[7] = {"rgb(255, 0, 0)", "rgb(255, 165, 0)", "rgb(255, 255, 0)", # "rgb(0, 255, 0)", "rgb(0, 127, 255)", "rgb(0, 0, 255)", # "rgb(139, 0, 255)"}; # private slots: # void changeColor(); # }; # #endif // QTBOXSTYLELABEL4_H # #include "qtboxstylelabel4.h" # QtBoxStyleLabel4::QtBoxStyleLabel4(QWidget *parent) # : QLabel(parent) # { # setText("Change text color"); # connect(timer, SIGNAL(timeout()), this, SLOT(changeColor())); # timer->start(100); # } # void QtBoxStyleLabel4::changeColor() # { # QString color = colorList[count]; # setStyleSheet(QString("color: %1").arg(color)); # count++; # if (count >= (sizeof(colorList)/sizeof(colorList[0]))) { # count = 0; # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/lcdnumber/__init__.py ================================================ from .func import demo1, demo2, demo3 from .style import demo1, demo2, demo3, demo4, demo5 ================================================ FILE: src/qtbox/demo/lcdnumber/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/lcdnumber/func/demo1.py ================================================ # PyQt from PyQt5.QtCore import QTimer, QTime from PyQt5.QtWidgets import QLCDNumber from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLCDNumber = createWidgetMenuBase(QLCDNumber) class QtBoxFuncLCDNumber1(QLCDNumber): def __init__(self): super(QtBoxFuncLCDNumber1, self).__init__(str(Path(__file__))) self.setFixedSize(150, 50) self.setDigitCount(8) self.update_display() self.timer = QTimer() self.timer.timeout.connect(self.update_display) self.timer.start(1000) def update_display(self): self.display(QTime.currentTime().toString()) # PyQt # PySide # from PySide2.QtCore import QTimer, QTime # from PySide2.QtWidgets import QLCDNumber # class QtBoxFuncLCDNumber1(QLCDNumber): # def __init__(self): # super(QtBoxFuncLCDNumber1, self).__init__() # self.setFixedSize(150, 50) # self.setDigitCount(8) # self.update_display() # self.timer = QTimer() # self.timer.timeout.connect(self.update_display) # self.timer.start(1000) # def update_display(self): # self.display(QTime.currentTime().toString()) # PySide # C++/Qt # #ifndef QTBOXFUNCLCDNUMBER1_H # #define QTBOXFUNCLCDNUMBER1_H # #include # #include # class QtBoxFuncLCDNumber1 : public QLCDNumber # { # Q_OBJECT # public: # QtBoxFuncLCDNumber1(QWidget *parent = nullptr); # private: # QTimer *timer = new QTimer(); # private slots: # void updateDisplay(); # }; # #endif // QTBOXFUNCLCDNUMBER1_H # #include "qtboxfunclcdnumber1.h" # #include # QtBoxFuncLCDNumber1::QtBoxFuncLCDNumber1(QWidget *parent) # : QLCDNumber(parent) # { # setFixedSize(150, 50); # setDigitCount(8); # updateDisplay(); # connect(timer, SIGNAL(timeout()), this, SLOT(updateDisplay())); # timer->start(1000); # } # void QtBoxFuncLCDNumber1::updateDisplay() # { # display(QTime::currentTime().toString()); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lcdnumber/func/demo2.py ================================================ # PyQt from PyQt5.QtCore import QTimer from PyQt5.QtWidgets import QLCDNumber from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLCDNumber = createWidgetMenuBase(QLCDNumber) class QtBoxFuncLCDNumber2(QLCDNumber): def __init__(self): super(QtBoxFuncLCDNumber2, self).__init__(str(Path(__file__))) self.setFixedSize(150, 50) self.text = "HELLO" self.setDigitCount(len(self.text)) self.display("") self.count = 0 self.timer = QTimer() self.timer.timeout.connect(self.update_display) self.timer.start(1000) def update_display(self): self.count += 1 if self.count > len(self.text): self.display(self.text+(self.count-len(self.text))*" ") else: self.display(self.text[0:self.count]) if self.count == 2*len(self.text): self.count = 0 # PyQt # PySide # from PySide2.QtCore import QTimer # from PySide2.QtWidgets import QLCDNumber # class QtBoxFuncLCDNumber2(QLCDNumber): # def __init__(self): # super(QtBoxFuncLCDNumber2, self).__init__() # self.setFixedSize(150, 50) # self.text = "HELLO" # self.setDigitCount(len(self.text)) # self.display("") # self.count = 0 # self.timer = QTimer() # self.timer.timeout.connect(self.update_display) # self.timer.start(1000) # def update_display(self): # self.count += 1 # if self.count > len(self.text): # self.display(self.text+(self.count-len(self.text))*" ") # else: # self.display(self.text[0:self.count]) # if self.count == 2*len(self.text): # self.count = 0 # PySide # C++/Qt # #ifndef QTBOXFUNCLCDNUMBER2_H # #define QTBOXFUNCLCDNUMBER2_H # #include # #include # #include # class QtBoxFuncLCDNumber2 : public QLCDNumber # { # Q_OBJECT # public: # QtBoxFuncLCDNumber2(QWidget *parent = nullptr); # private: # int count = 0; # QString text = "HELLO"; # QTimer *timer = new QTimer(); # private slots: # void updateDisplay(); # }; # #endif // QTBOXFUNCLCDNUMBER2_H # #include "qtboxfunclcdnumber2.h" # QtBoxFuncLCDNumber2::QtBoxFuncLCDNumber2(QWidget *parent) # : QLCDNumber(parent) # { # setFixedSize(150, 50); # setDigitCount(text.size()); # display(""); # connect(timer, SIGNAL(timeout()), this, SLOT(updateDisplay())); # timer->start(1000); # } # void QtBoxFuncLCDNumber2::updateDisplay() # { # count++; # if (count > text.size()) { # QString emptyString = ""; # for (int i=0; i # #include # #include # class QtBoxFuncLCDNumber3 : public QLCDNumber # { # Q_OBJECT # # public: # QtBoxFuncLCDNumber3(QWidget *parent = nullptr); # private: # int count = 0; # QTimer *timer = new QTimer(); # QTime *time = new QTime(1, 0, 0, 0); # private slots: # void updateDisplay(); # }; # #endif // QTBOXFUNCLCDNUMBER3_H # #include "qtboxfunclcdnumber3.h" # QtBoxFuncLCDNumber3::QtBoxFuncLCDNumber3(QWidget *parent) # : QLCDNumber(parent) # { # setFixedSize(150, 50); # setDigitCount(8); # updateDisplay(); # connect(timer, SIGNAL(timeout()), this, SLOT(updateDisplay())); # timer->start(1000); # } # void QtBoxFuncLCDNumber3::updateDisplay() # { # count++; # int timeLeft = time->addSecs(-count).second(); # display(time->addSecs(-count).toString("hh:mm:ss")); # if (timeLeft <= 0) { # time->setHMS(1, 0, 0, 0); # count = 0; # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/lcdnumber/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/lcdnumber/style/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QLCDNumber from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLCDNumber = createWidgetMenuBase(QLCDNumber) class QtBoxStyleLCDNumber1(QLCDNumber): def __init__(self): super(QtBoxStyleLCDNumber1, self).__init__(str(Path(__file__))) self.setFixedSize(150, 50) self.setDigitCount(6) self.display(123456) self.setSegmentStyle(QLCDNumber.Flat) self.setStyleSheet(""" QLCDNumber { background-color: #98a780; border: none; } """) # PyQt # PySide # from PySide2.QtWidgets import QLCDNumber # class QtBoxStyleLCDNumber1(QLCDNumber): # def __init__(self): # super(QtBoxStyleLCDNumber1, self).__init__() # self.setFixedSize(150, 50) # self.setDigitCount(6) # self.display(123456) # self.setSegmentStyle(QLCDNumber.Flat) # self.setStyleSheet(""" # QLCDNumber { # background-color: #98a780; # border: none; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELCDNUMBER1_H # #define QTBOXSTYLELCDNUMBER1_H # #include # class QtBoxStyleLCDNumber1 : public QLCDNumber # { # Q_OBJECT # public: # QtBoxStyleLCDNumber1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLELCDNUMBER1_H # #include "qtboxstylelcdnumber1.h" # QtBoxStyleLCDNumber1::QtBoxStyleLCDNumber1(QWidget *parent) # : QLCDNumber(parent) # { # setFixedSize(150, 50); # setDigitCount(6); # display(123456); # setSegmentStyle(QLCDNumber::Flat); # setStyleSheet(R"( # QLCDNumber { # background-color: #98a780; # border: none; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lcdnumber/style/demo2.py ================================================ # PyQt from PyQt5.QtWidgets import QLCDNumber from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLCDNumber = createWidgetMenuBase(QLCDNumber) class QtBoxStyleLCDNumber2(QLCDNumber): def __init__(self): super(QtBoxStyleLCDNumber2, self).__init__(str(Path(__file__))) self.setFixedSize(150, 50) self.setDigitCount(6) self.display(123456) self.setSegmentStyle(QLCDNumber.Flat) self.setStyleSheet(""" QLCDNumber { background-color: #0130f2; border: none; color: white; } """) # PyQt # PySide # from PySide2.QtWidgets import QLCDNumber # class QtBoxStyleLCDNumber2(QLCDNumber): # def __init__(self): # super(QtBoxStyleLCDNumber2, self).__init__() # self.setFixedSize(150, 50) # self.setDigitCount(6) # self.display(123456) # self.setSegmentStyle(QLCDNumber.Flat) # self.setStyleSheet(""" # QLCDNumber { # background-color: #0130f2; # border: none; # color: white; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELCDNUMBER2_H # #define QTBOXSTYLELCDNUMBER2_H # #include # class QtBoxStyleLCDNumber2 : public QLCDNumber # { # Q_OBJECT # public: # QtBoxStyleLCDNumber2(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLELCDNUMBER2_H # #include "qtboxstylelcdnumber2.h" # QtBoxStyleLCDNumber2::QtBoxStyleLCDNumber2(QWidget *parent) # : QLCDNumber(parent) # { # setFixedSize(150, 50); # setDigitCount(6); # display(123456); # setSegmentStyle(QLCDNumber::Flat); # setStyleSheet(R"( # QLCDNumber { # background-color: #0130f2; # border: none; # color: white; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lcdnumber/style/demo3.py ================================================ # PyQt from PyQt5.QtWidgets import QLCDNumber from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLCDNumber = createWidgetMenuBase(QLCDNumber) class QtBoxStyleLCDNumber3(QLCDNumber): def __init__(self): super(QtBoxStyleLCDNumber3, self).__init__(str(Path(__file__))) self.setFixedSize(150, 50) self.setDigitCount(6) self.display(123456) self.setSegmentStyle(QLCDNumber.Flat) self.setStyleSheet(""" QLCDNumber { background-color: #98a7a7; border: none; color: black; } """) # PyQt # PySide # from PySide2.QtWidgets import QLCDNumber # class QtBoxStyleLCDNumber3(QLCDNumber): # def __init__(self): # super(QtBoxStyleLCDNumber3, self).__init__() # self.setFixedSize(150, 50) # self.setDigitCount(6) # self.display(123456) # self.setSegmentStyle(QLCDNumber.Flat) # self.setStyleSheet(""" # QLCDNumber { # background-color: #98a7a7; # border: none; # color: black; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELCDNUMBER3_H # #define QTBOXSTYLELCDNUMBER3_H # #include # class QtBoxStyleLCDNumber3 : public QLCDNumber # { # Q_OBJECT # public: # QtBoxStyleLCDNumber3(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLELCDNUMBER3_H # #include "qtboxstylelcdnumber3.h" # QtBoxStyleLCDNumber3::QtBoxStyleLCDNumber3(QWidget *parent) # : QLCDNumber(parent) # { # setFixedSize(150, 50); # setDigitCount(6); # display(123456); # setSegmentStyle(QLCDNumber::Flat); # setStyleSheet(R"( # QLCDNumber { # background-color: #98a7a7; # border: none; # color: black; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lcdnumber/style/demo4.py ================================================ # PyQt from PyQt5.QtWidgets import QLCDNumber from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLCDNumber = createWidgetMenuBase(QLCDNumber) class QtBoxStyleLCDNumber4(QLCDNumber): def __init__(self): super(QtBoxStyleLCDNumber4, self).__init__(str(Path(__file__))) self.setFixedSize(150, 50) self.setDigitCount(6) self.display(123456) self.setSegmentStyle(QLCDNumber.Flat) self.setStyleSheet(""" QLCDNumber { background-color: transparent; border: none; color: black; } """) # PyQt # PySide # from PySide2.QtWidgets import QLCDNumber # class QtBoxStyleLCDNumber3(QLCDNumber): # def __init__(self): # super(QtBoxStyleLCDNumber3, self).__init__() # self.setFixedSize(150, 50) # self.setDigitCount(6) # self.display(123456) # self.setSegmentStyle(QLCDNumber.Flat) # self.setStyleSheet(""" # QLCDNumber { # background-color: transparent; # border: none; # color: black; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELCDNUMBER4_H # #define QTBOXSTYLELCDNUMBER4_H # #include # class QtBoxStyleLCDNumber4 : public QLCDNumber # { # Q_OBJECT # public: # QtBoxStyleLCDNumber4(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLELCDNUMBER4_H # #include "qtboxstylelcdnumber4.h" # QtBoxStyleLCDNumber4::QtBoxStyleLCDNumber4(QWidget *parent) # : QLCDNumber(parent) # { # setFixedSize(150, 50); # setDigitCount(6); # display(123456); # setSegmentStyle(QLCDNumber::Flat); # setStyleSheet(R"( # QLCDNumber { # background-color: transparent; # border: none; # color: black; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lcdnumber/style/demo5.py ================================================ # PyQt from PyQt5.QtWidgets import QLCDNumber from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLCDNumber = createWidgetMenuBase(QLCDNumber) class QtBoxStyleLCDNumber5(QLCDNumber): def __init__(self): super(QtBoxStyleLCDNumber5, self).__init__(str(Path(__file__))) self.setFixedSize(150, 50) self.setDigitCount(6) self.display(123456) self.setSegmentStyle(QLCDNumber.Flat) self.setStyleSheet(""" QLCDNumber { background-color: black; border: none; color: red; } """) # PyQt # PySide # from PySide2.QtWidgets import QLCDNumber # class QtBoxStyleLCDNumber3(QLCDNumber): # def __init__(self): # super(QtBoxStyleLCDNumber3, self).__init__() # self.setFixedSize(150, 50) # self.setDigitCount(6) # self.display(123456) # self.setSegmentStyle(QLCDNumber.Flat) # self.setStyleSheet(""" # QLCDNumber { # background-color: black; # border: none; # color: red; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELCDNUMBER5_H # #define QTBOXSTYLELCDNUMBER5_H # #include # class QtBoxStyleLCDNumber5 : public QLCDNumber # { # Q_OBJECT # public: # QtBoxStyleLCDNumber5(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLELCDNUMBER5_H # #include "qtboxstylelcdnumber5.h" # QtBoxStyleLCDNumber5::QtBoxStyleLCDNumber5(QWidget *parent) # : QLCDNumber(parent) # { # setFixedSize(150, 50); # setDigitCount(6); # display(123456); # setSegmentStyle(QLCDNumber::Flat); # setStyleSheet(R"( # QLCDNumber { # background-color: black; # border: none; # color: red; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/__init__.py ================================================ from .func import demo1, demo2, demo3, demo4, demo5 from .style import demo1, demo2, demo3, demo4, demo5, demo6, demo7 ================================================ FILE: src/qtbox/demo/lineedit/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/lineedit/func/demo1.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QLineEdit, QMessageBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) class QtBoxFuncLineEdit1(QLineEdit): def __init__(self): super(QtBoxFuncLineEdit1, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.setPlaceholderText("press Enter or Return") def keyPressEvent(self, event): super(QtBoxFuncLineEdit1, self).keyPressEvent(event) if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return: QMessageBox.information(self, "Qt Box", "Key Enter or Return pressed") # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QLineEdit, QMessageBox # class QtBoxFuncLineEdit1(QLineEdit): # def __init__(self): # super(QtBoxFuncLineEdit1, self).__init__() # self.setFixedSize(150, 30) # self.setPlaceholderText("press Enter or Return") # def keyPressEvent(self, event): # super(QtBoxFuncLineEdit1, self).keyPressEvent(event) # if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return: # QMessageBox.information(self, "Qt Box", "Key Enter or Return pressed") # PySide # C++/Qt # #ifndef QTBOXFUNCLINEEDIT1_H # #define QTBOXFUNCLINEEDIT1_H # #include # #include # class QtBoxFuncLineEdit1 : public QLineEdit # { # Q_OBJECT # protected: # void keyPressEvent(QKeyEvent *event); # public: # QtBoxFuncLineEdit1(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCLINEEDIT1_H # #include "qtboxfunclineedit1.h" # #include # #include # QtBoxFuncLineEdit1::QtBoxFuncLineEdit1(QWidget *parent) # : QLineEdit(parent) # { # setFixedSize(150, 30); # setPlaceholderText("press Enter or Return"); # } # void QtBoxFuncLineEdit1::keyPressEvent(QKeyEvent *event) # { # QLineEdit::keyPressEvent(event); # if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { # QMessageBox::information(this, "Qt Box", "Key Enter or Return pressed"); # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/func/demo2.py ================================================ # PyQt from PyQt5.QtGui import QRegExpValidator from PyQt5.QtWidgets import QLineEdit from PyQt5.QtCore import QRegExp from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) class QtBoxFuncLineEdit2(QLineEdit): def __init__(self): super(QtBoxFuncLineEdit2, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.setPlaceholderText("Numbers only") reg_exp = QRegExp("[0-9]+") self.setValidator(QRegExpValidator(reg_exp)) # PyQt # PySide # from PySide2.QtGui import QRegExpValidator # from PySide2.QtWidgets import QLineEdit # from PySide2.QtCore import QRegExp # class QtBoxFuncLineEdit2(QLineEdit): # def __init__(self): # super(QtBoxFuncLineEdit2, self).__init__() # self.setFixedSize(150, 30) # self.setPlaceholderText("Numbers only") # reg_exp = QRegExp("[0-9]+") # self.setValidator(QRegExpValidator(reg_exp)) # PySide # C++/Qt # #ifndef QTBOXFUNCLINEEDIT2_H # #define QTBOXFUNCLINEEDIT2_H # #include # class QtBoxFuncLineEdit2 : public QLineEdit # { # Q_OBJECT # public: # QtBoxFuncLineEdit2(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCLINEEDIT2_H # #include "qtboxfunclineedit2.h" # #include # #include # QtBoxFuncLineEdit2::QtBoxFuncLineEdit2(QWidget *parent) # : QLineEdit(parent) # { # setFixedSize(150, 30); # setPlaceholderText("Numbers Only"); # # QRegularExpression regExp = QRegularExpression("[0-9]+"); # setValidator(new QRegularExpressionValidator(regExp)); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/func/demo3.py ================================================ # PyQt from PyQt5.QtGui import QRegExpValidator, QValidator from PyQt5.QtWidgets import QLineEdit, QMessageBox from PyQt5.QtCore import QRegExp, Qt from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) class QtBoxFuncLineEdit3(QLineEdit): def __init__(self): super(QtBoxFuncLineEdit3, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.setPlaceholderText("example@email.com") reg_exp = QRegExp("[a-zA-Z0-9-_]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$") self.setValidator(QRegExpValidator(reg_exp)) def validate_email(self): if self.validator().validate(self.text(), 0)[0] == QValidator.Acceptable: QMessageBox.information(self, "Qt Box", "Correct email format") else: QMessageBox.information(self, "Qt Box", "Wrong email format") def keyPressEvent(self, event): super(QtBoxFuncLineEdit3, self).keyPressEvent(event) if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return: self.validate_email() # PyQt # PySide # from PySide2.QtGui import QRegExpValidator, QValidator # from PySide2.QtWidgets import QLineEdit, QMessageBox # from PySide2.QtCore import QRegExp, Qt # class QtBoxFuncLineEdit3(QLineEdit): # def __init__(self): # super(QtBoxFuncLineEdit3, self).__init__() # self.setFixedSize(150, 30) # self.setPlaceholderText("example@email.com") # reg_exp = QRegExp("[a-zA-Z0-9-_]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$") # self.setValidator(QRegExpValidator(reg_exp)) # def validate_email(self): # if self.validator().validate(self.text(), 0)[0] == QValidator.Acceptable: # QMessageBox.information(self, "Qt Box", "Correct email format") # else: # QMessageBox.information(self, "Qt Box", "Wrong email format") # def keyPressEvent(self, event): # super(QtBoxFuncLineEdit3, self).keyPressEvent(event) # if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return: # self.validate_email() # PySide # C++/Qt # #ifndef QTBOXFUNCLINEEDIT3_H # #define QTBOXFUNCLINEEDIT3_H # #include # #include # class QtBoxFuncLineEdit3 : public QLineEdit # { # Q_OBJECT # protected: # void keyPressEvent(QKeyEvent *event); # public: # QtBoxFuncLineEdit3(QWidget *parent = nullptr); # private: # void validateEmail(); # }; # #endif // QTBOXFUNCLINEEDIT3_H # #include "qtboxfunclineedit3.h" # #include # #include # #include # #include # #include # QtBoxFuncLineEdit3::QtBoxFuncLineEdit3(QWidget *parent) # : QLineEdit(parent) # { # setFixedSize(150, 30); # setPlaceholderText("example@email.com"); # QRegularExpression regExp = QRegularExpression("[a-zA-Z0-9-_]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$"); # setValidator(new QRegularExpressionValidator(regExp)); # } # void QtBoxFuncLineEdit3::validateEmail() { # QString textToValidate = text(); # int pos = 0; # if (validator()->validate(textToValidate, pos) == QValidator::Acceptable) { # QMessageBox::information(this, "Qt Box", "Correct email format"); # } # else { # QMessageBox::information(this, "Qt Box", "Wrong email format"); # } # } # void QtBoxFuncLineEdit3::keyPressEvent(QKeyEvent *event) # { # QLineEdit::keyPressEvent(event); # if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { # validateEmail(); # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/func/demo4.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QLineEdit, QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) PATH_TO_OPEN_EYE_IMG = str(Path(__file__).parent.parent.parent.parent / "res/images/open_eye.png").replace("\\", "/") PATH_TO_CLOSED_EYE_IMG = str(Path(__file__).parent.parent.parent.parent / "res/images/closed_eye.png").replace("\\", "/") class QtBoxFuncLineEdit4(QLineEdit): def __init__(self): super(QtBoxFuncLineEdit4, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.setEchoMode(QLineEdit.Password) self.setPlaceholderText("Enter password") self.setStyleSheet(""" QLineEdit { padding-right: 25px; } """) self.eye_btn = QPushButton(self) self.eye_btn.setIcon(QIcon(PATH_TO_CLOSED_EYE_IMG)) self.eye_btn.setFixedSize(self.height(), self.height()) self.eye_btn.move(self.width()-self.eye_btn.width(), 0) self.eye_btn.clicked.connect(self.change_echo_mode) self.eye_btn.setCursor(Qt.PointingHandCursor) self.eye_btn.setStyleSheet(""" QPushButton { border: none; } """) def change_echo_mode(self): if self.echoMode() == QLineEdit.Normal: self.setEchoMode(QLineEdit.Password) self.eye_btn.setIcon(QIcon(PATH_TO_CLOSED_EYE_IMG)) else: self.setEchoMode(QLineEdit.Normal) self.eye_btn.setIcon(QIcon(PATH_TO_OPEN_EYE_IMG)) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtGui import QIcon # from PySide2.QtWidgets import QLineEdit, QPushButton # class QtBoxFuncLineEdit4(QLineEdit): # def __init__(self): # super(QtBoxFuncLineEdit4, self).__init__(str(Path(__file__))) # self.setFixedSize(150, 30) # self.setEchoMode(QLineEdit.Password) # self.setPlaceholderText("Enter password") # self.setStyleSheet(""" # QLineEdit { # padding-right: 25px; # } # """) # self.eye_btn = QPushButton(self) # self.eye_btn.setIcon(QIcon(PATH_TO_CLOSED_EYE_IMG)) # self.eye_btn.setFixedSize(self.height(), self.height()) # self.eye_btn.move(self.width()-self.eye_btn.width(), 0) # self.eye_btn.clicked.connect(self.change_echo_mode) # self.eye_btn.setCursor(Qt.PointingHandCursor) # self.eye_btn.setStyleSheet(""" # QPushButton { # border: none; # } # """) # def change_echo_mode(self): # if self.echoMode() == QLineEdit.Normal: # self.setEchoMode(QLineEdit.Password) # self.eye_btn.setIcon(QIcon(PATH_TO_CLOSED_EYE_IMG)) # else: # self.setEchoMode(QLineEdit.Normal) # self.eye_btn.setIcon(QIcon(PATH_TO_OPEN_EYE_IMG)) # PySide # C++/Qt # #ifndef QTBOXFUNCLINEEDIT4_H # #define QTBOXFUNCLINEEDIT4_H # #include # #include # class QtBoxFuncLineEdit4 : public QLineEdit # { # Q_OBJECT # public: # QtBoxFuncLineEdit4(QWidget *parent = nullptr); # private: # QPushButton *eyeBtn = new QPushButton(this); # private slots: # void changeEchoMode(); # }; # #endif // QTBOXFUNCLINEEDIT4_H # #include "qtboxfunclineedit4.h" # #include # #include # QtBoxFuncLineEdit4::QtBoxFuncLineEdit4(QWidget *parent) # : QLineEdit(parent) # { # setFixedSize(150, 30); # setEchoMode(QLineEdit::Password); # setPlaceholderText("Enter password"); # setStyleSheet("QLineEdit {padding-right: 25px;}"); # eyeBtn->setIcon(QIcon(PATH_TO_CLOSED_EYE_IMG)); # eyeBtn->setFixedSize(height(), height()); # eyeBtn->move(width()-eyeBtn->width(), 0); # connect(eyeBtn, SIGNAL(clicked()), this, SLOT(changeEchoMode())); # eyeBtn->setCursor(Qt::PointingHandCursor); # eyeBtn->setStyleSheet("QPushButton {border: none;}"); # } # void QtBoxFuncLineEdit4::changeEchoMode() # { # if (echoMode() == QLineEdit::Normal) { # setEchoMode(QLineEdit::Password); # eyeBtn->setIcon(QIcon(PATH_TO_CLOSED_EYE_IMG)); # } # else { # setEchoMode(QLineEdit::Normal); # eyeBtn->setIcon(QIcon(PATH_TO_OPEN_EYE_IMG)); # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/func/demo5.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QLineEdit, QCompleter from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) class QtBoxFuncLineEdit5(QLineEdit): def __init__(self): super(QtBoxFuncLineEdit5, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.setPlaceholderText("Type P or Q") comp = QCompleter(["PyQt", "Qt", "Qt Box", "PySide", "Python"]) comp.setFilterMode(Qt.MatchContains) self.setCompleter(comp) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QLineEdit, QCompleter # class QtBoxFuncLineEdit5(QLineEdit): # def __init__(self): # super(QtBoxFuncLineEdit5, self).__init__() # self.setFixedSize(150, 30) # self.setPlaceholderText("Type P or Q") # comp = QCompleter(["PyQt", "Qt", "Qt Box", "PySide", "Python"]) # comp.setFilterMode(Qt.MatchContains) # self.setCompleter(comp) # PySide # C++/Qt # #ifndef QTBOXFUNCLINEEDIT5_H # #define QTBOXFUNCLINEEDIT5_H # #include # class QtBoxFuncLineEdit5 : public QLineEdit # { # Q_OBJECT # public: # QtBoxFuncLineEdit5(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCLINEEDIT5_H # #include "qtboxfunclineedit5.h" # #include # #include # QtBoxFuncLineEdit5::QtBoxFuncLineEdit5(QWidget *parent) # : QLineEdit(parent) # { # setFixedSize(150, 30); # setPlaceholderText("Type P or Q"); # QCompleter *comp = new QCompleter({"PyQt", "Qt", "Qt Box", "PySide", "Python"}); # comp->setFilterMode(Qt::MatchContains); # setCompleter(comp); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/lineedit/style/demo1.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QLineEdit, QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) PATH_TO_IMG = str(Path(__file__).parent.parent.parent.parent / "res/images/search.png").replace("\\", "/") class QtBoxStyleLineEdit1(QLineEdit): def __init__(self): super(QtBoxStyleLineEdit1, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.setPlaceholderText("search") self.search_btn = QPushButton(self) self.search_btn.setIcon(QIcon(PATH_TO_IMG)) self.search_btn.setCursor(Qt.PointingHandCursor) self.search_btn.setFixedSize(self.height(), self.height()) self.search_btn.move(self.width()-self.search_btn.width(), 0) self.setStyleSheet(""" QPushButton { border: none; } QLineEdit { background-color: #232324; border: 1px solid gray; border-radius: 3px; padding-left: 2px; padding-right: 25px; color: #f0f0f0; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtGui import QIcon # from PySide2.QtWidgets import QLineEdit, QPushButton # class QtBoxStyleLineEdit1(QLineEdit): # def __init__(self): # super(QtBoxStyleLineEdit1, self).__init__() # self.setFixedSize(150, 30) # self.setPlaceholderText("search") # self.search_btn = QPushButton(self) # self.search_btn.setIcon(QIcon(PATH_TO_IMG)) # self.search_btn.setCursor(Qt.PointingHandCursor) # self.search_btn.setFixedSize(self.height(), self.height()) # self.search_btn.move(self.width()-self.search_btn.width(), 0) # self.setStyleSheet(""" # QPushButton { # border: none; # } # QLineEdit { # background-color: #232324; # border: 1px solid gray; # border-radius: 3px; # padding-left: 2px; # padding-right: 25px; # color: #f0f0f0; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELINEEDIT1_H # #define QTBOXSTYLELINEEDIT1_H # #include # #include # class QtBoxStyleLineEdit1 : public QLineEdit # { # Q_OBJECT # public: # QtBoxStyleLineEdit1(QWidget *parent = nullptr); # private: # QPushButton *searchBtn = new QPushButton(this); # }; # #endif // QTBOXSTYLELINEEDIT1_H # #include "qtboxstylelineedit1.h" # #include # QtBoxStyleLineEdit1::QtBoxStyleLineEdit1(QWidget *parent) # : QLineEdit(parent) # { # setFixedSize(150, 30); # setPlaceholderText("search"); # searchBtn->setIcon(QIcon(":res/images/search.png")); # searchBtn->setCursor(Qt::PointingHandCursor); # searchBtn->setFixedSize(height(), height()); # searchBtn->move(width()-searchBtn->width(), 0); # setStyleSheet(R"( # QPushButton { # border: none; # } # QLineEdit { # background-color: #232324; # border: 1px solid gray; # border-radius: 3px; # padding-left: 2px; # padding-right: 25px; # color: #f0f0f0; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/style/demo2.py ================================================ # PyQt from PyQt5.QtWidgets import QLineEdit, QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) class QtBoxStyleLineEdit2(QLineEdit): def __init__(self): super(QtBoxStyleLineEdit2, self).__init__(str(Path(__file__))) self.setFixedSize(150, 50) self.setStyleSheet(""" QLineEdit { border: 1px solid gray; border-radius: 5px; padding-top: 14px; padding-left: 2px; padding-right: 2px; } """) self.label = QLabel(self) self.label.setText("Name") self.label.move(5, 16) self.label.setStyleSheet(""" QLabel { color: gray; font-size: 16px; } """) def focusInEvent(self, event): super(QtBoxStyleLineEdit2, self).focusInEvent(event) self.label.move(5, 5) self.label.setStyleSheet(""" QLabel { color: black; font-size: 12px; } """) def focusOutEvent(self, event): super(QtBoxStyleLineEdit2, self).focusOutEvent(event) if self.text(): return self.label.move(5, 16) self.label.setStyleSheet(""" QLabel { color: gray; font-size: 16px; } """) # PyQt # PySide # from PySide2.QtWidgets import QLineEdit, QLabel # class QtBoxStyleLineEdit2(QLineEdit): # def __init__(self): # super(QtBoxStyleLineEdit2, self).__init__() # self.setFixedSize(150, 50) # self.setStyleSheet(""" # QLineEdit { # border: 1px solid gray; # border-radius: 5px; # padding-top: 14px; # padding-left: 2px; # padding-right: 2px; # } # """) # self.label = QLabel(self) # self.label.setText("Name") # self.label.move(5, 16) # self.label.setStyleSheet(""" # QLabel { # color: gray; # font-size: 16px; # } # """) # def focusInEvent(self, event): # super(QtBoxStyleLineEdit2, self).focusInEvent(event) # self.label.move(5, 5) # self.label.setStyleSheet(""" # QLabel { # color: black; # font-size: 12px; # } # """) # def focusOutEvent(self, event): # super(QtBoxStyleLineEdit2, self).focusOutEvent(event) # if self.text(): # return # self.label.move(5, 16) # self.label.setStyleSheet(""" # QLabel { # color: gray; # font-size: 16px; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELINEEDIT2_H # #define QTBOXSTYLELINEEDIT2_H # #include # #include # #include # class QtBoxStyleLineEdit2 : public QLineEdit # { # Q_OBJECT # public: # QtBoxStyleLineEdit2(QWidget *parent = nullptr); # protected: # void focusInEvent(QFocusEvent *event); # void focusOutEvent(QFocusEvent *event); # private: # QLabel *label = new QLabel(this); # }; # #endif // QTBOXSTYLELINEEDIT2_H # #include "qtboxstylelineedit2.h" # #include # QtBoxStyleLineEdit2::QtBoxStyleLineEdit2(QWidget *parent) # : QLineEdit(parent) # { # setFixedSize(150, 50); # setStyleSheet(R"( # QLineEdit { # border: 1px solid gray; # border-radius: 5px; # padding-top: 14px; # padding-left: 2px; # padding-right: 2px; # } # )"); # label->setText("Name"); # label->move(5, 16); # label->setStyleSheet(R"( # QLabel { # color: gray; # font-size: 16px; # } # )"); # } # void QtBoxStyleLineEdit2::focusInEvent(QFocusEvent *event) # { # QLineEdit::focusInEvent(event); # label->move(5, 5); # label->setStyleSheet(R"( # QLabel { # color: black; # font-size: 12px; # } # )"); # } # void QtBoxStyleLineEdit2::focusOutEvent(QFocusEvent *event) # { # QLineEdit::focusOutEvent(event); # if (!text().isEmpty()) { # return; # } # label->move(5, 16); # label->setStyleSheet(R"( # QLabel { # color: gray; # font-size: 16px; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/style/demo3.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QLineEdit, QLabel from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) class QtBoxStyleLineEdit3(QLineEdit): def __init__(self): super(QtBoxStyleLineEdit3, self).__init__(str(Path(__file__))) self.setAttribute(Qt.WA_MacShowFocusRect, False) self.setPlaceholderText("Enter username") self.setFixedSize(180, 30) self.setStyleSheet(""" QLineEdit { border: 1px solid lightgray; border-radius: 5px; border-top-left-radius: 10px; border-bottom-left-radius: 10px; padding-left: 62px; padding-right: 5px; } """) self.label = QLabel(self) self.label.setText("Qt Box") self.label.setFixedSize(60, 30) self.label.move(0, 0) self.label.setStyleSheet(""" QLabel { background-color: #f8f9fb; color: black; font-size: 15px; padding-left: 3px; border: 1px solid lightgray; border-top-left-radius: 10px; border-bottom-left-radius: 10px; } QLabel:hover { background-color: #ebecf0; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QLineEdit, QLabel # class QtBoxStyleLineEdit3(QLineEdit): # def __init__(self): # super(QtBoxStyleLineEdit3, self).__init__() # self.setAttribute(Qt.WA_MacShowFocusRect, False) # self.setPlaceholderText("Enter username") # self.setFixedSize(180, 30) # self.setStyleSheet(""" # QLineEdit { # border: 1px solid lightgray; # border-radius: 5px; # border-top-left-radius: 10px; # border-bottom-left-radius: 10px; # padding-left: 62px; # padding-right: 5px; # } # """) # self.label = QLabel(self) # self.label.setText("Qt Box") # self.label.setFixedSize(60, 30) # self.label.move(0, 0) # self.label.setStyleSheet(""" # QLabel { # background-color: #f8f9fb; # color: black; # font-size: 15px; # padding-left: 3px; # border: 1px solid lightgray; # border-top-left-radius: 10px; # border-bottom-left-radius: 10px; # } # QLabel:hover { # background-color: #ebecf0; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELINEEDIT3_H # #define QTBOXSTYLELINEEDIT3_H # #include # #include # class QtBoxStyleLineEdit3 : public QLineEdit # { # Q_OBJECT # public: # QtBoxStyleLineEdit3(QWidget *parent = nullptr); # private: # QLabel *label = new QLabel(this); # }; # #endif // QTBOXSTYLELINEEDIT3_H # #include "qtboxstylelineedit3.h" # QtBoxStyleLineEdit3::QtBoxStyleLineEdit3(QWidget *parent) # : QLineEdit(parent) # { # setAttribute(Qt::WA_MacShowFocusRect, false); # setPlaceholderText("Enter username"); # setFixedSize(180, 30); # setStyleSheet(R"( # QLineEdit { # border: 1px solid lightgray; # border-radius: 5px; # border-top-left-radius: 10px; # border-bottom-left-radius: 10px; # padding-left: 62px; # padding-right: 5px; # } # )"); # label->setText("Qt Box"); # label->setFixedSize(60, 30); # label->move(0, 0); # label->setStyleSheet(R"( # QLabel { # background-color: #f8f9fb; # color: black; # font-size: 15px; # padding-left: 3px; # border: 1px solid lightgray; # border-top-left-radius: 10px; # border-bottom-left-radius: 10px; # } # QLabel:hover { # background-color: #ebecf0; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/style/demo4.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QLineEdit, QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) class QtBoxStyleLineEdit4(QLineEdit): def __init__(self): super(QtBoxStyleLineEdit4, self).__init__(str(Path(__file__))) self.setAttribute(Qt.WA_MacShowFocusRect, False) self.setPlaceholderText("search") self.setFixedSize(180, 30) self.setStyleSheet(""" QLineEdit { border: 1px solid lightgray; border-radius: 5px; padding-left: 5px; padding-right: 60px; } """) self.search_btn = QPushButton(self) self.search_btn.setText("Search") self.search_btn.setFixedSize(60, self.height()) self.search_btn.setCursor(Qt.PointingHandCursor) self.search_btn.move(self.width()-self.search_btn.width(), 0) self.search_btn.setStyleSheet(""" QPushButton { background-color: #2a70f4; color: white; font-size: 13px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; } QPushButton:hover { background-color: #2361d0; } QPushButton:pressed { background-color: #2058bc; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QLineEdit, QPushButton # class QtBoxStyleLineEdit4(QLineEdit): # def __init__(self): # super(QtBoxStyleLineEdit4, self).__init__() # self.setAttribute(Qt.WA_MacShowFocusRect, False) # self.setPlaceholderText("search") # self.setFixedSize(180, 30) # self.setStyleSheet(""" # QLineEdit { # border: 1px solid lightgray; # border-radius: 5px; # padding-left: 5px; # padding-right: 60px; # } # """) # self.search_btn = QPushButton(self) # self.search_btn.setText("Search") # self.search_btn.setFixedSize(60, self.height()) # self.search_btn.setCursor(Qt.PointingHandCursor) # self.search_btn.move(self.width()-self.search_btn.width(), 0) # self.search_btn.setStyleSheet(""" # QPushButton { # background-color: #2a70f4; # color: white; # font-size: 13px; # border-top-right-radius: 5px; # border-bottom-right-radius: 5px; # } # QPushButton:hover { # background-color: #2361d0; # } # QPushButton:pressed { # background-color: #2058bc; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELINEEDIT4_H # #define QTBOXSTYLELINEEDIT4_H # #include # #include # class QtBoxStyleLineEdit4 : public QLineEdit # { # Q_OBJECT # public: # QtBoxStyleLineEdit4(QWidget *parent = nullptr); # private: # QPushButton *searchBtn = new QPushButton(this); # }; # #endif // QTBOXSTYLELINEEDIT4_H # #include "qtboxstylelineedit4.h" # QtBoxStyleLineEdit4::QtBoxStyleLineEdit4(QWidget *parent) # : QLineEdit(parent) # { # setAttribute(Qt::WA_MacShowFocusRect, false); # setPlaceholderText("search"); # setFixedSize(180, 30); # setStyleSheet(R"( # QLineEdit { # border: 1px solid lightgray; # border-radius: 5px; # padding-left: 5px; # padding-right: 60px; # } # )"); # searchBtn->setText("Search"); # searchBtn->setFixedSize(60, height()); # searchBtn->setCursor(Qt::PointingHandCursor); # searchBtn->move(width()-searchBtn->width(), 0); # searchBtn->setStyleSheet(R"( # QPushButton { # background-color: #2a70f4; # color: white; # font-size: 13px; # border-top-right-radius: 5px; # border-bottom-right-radius: 5px; # } # QPushButton:hover { # background-color: #2361d0; # } # QPushButton:pressed { # background-color: #2058bc; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/style/demo5.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QLineEdit, QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) class QtBoxStyleLineEdit5(QLineEdit): def __init__(self): super(QtBoxStyleLineEdit5, self).__init__(str(Path(__file__))) self.setAttribute(Qt.WA_MacShowFocusRect, False) self.setPlaceholderText("Enter username") self.setFixedSize(150, 30) self.setStyleSheet(""" QLineEdit { border-top: none; border-left: none; border-right: none; border-bottom: 1px solid black; background-color: transparent; } QLineEdit:focus { border-bottom: 1px solid #2a70f4; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QLineEdit, QPushButton # class QtBoxStyleLineEdit5(QLineEdit): # def __init__(self): # super(QtBoxStyleLineEdit5, self).__init__() # self.setAttribute(Qt.WA_MacShowFocusRect, False) # self.setPlaceholderText("Enter username") # self.setFixedSize(150, 30) # self.setStyleSheet(""" # QLineEdit { # border-top: none; # border-left: none; # border-right: none; # border-bottom: 1px solid black; # background-color: transparent; # } # QLineEdit:focus { # border-bottom: 1px solid #2a70f4; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELINEEDIT5_H # #define QTBOXSTYLELINEEDIT5_H # #include # class QtBoxStyleLineEdit5 : public QLineEdit # { # Q_OBJECT # public: # QtBoxStyleLineEdit5(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLELINEEDIT5_H # #include "qtboxstylelineedit5.h" # QtBoxStyleLineEdit5::QtBoxStyleLineEdit5(QWidget *parent) # : QLineEdit(parent) # { # setAttribute(Qt::WA_MacShowFocusRect, false); # setPlaceholderText("Enter username"); # setFixedSize(150, 30); # setStyleSheet(R"( # QLineEdit { # border-top: none; # border-left: none; # border-right: none; # border-bottom: 1px solid black; # background-color: transparent; # } # QLineEdit:focus { # border-bottom: 1px solid #2a70f4; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/style/demo6.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QLineEdit from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) class QtBoxStyleLineEdit6(QLineEdit): def __init__(self): super(QtBoxStyleLineEdit6, self).__init__(str(Path(__file__))) self.setMaxLength(1) self.setFixedSize(50, 50) self.setAlignment(Qt.AlignCenter) self.setStyleSheet(""" QLineEdit { font-size: 25px; border: 2px solid black; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QLineEdit # class QtBoxStyleLineEdit6(QLineEdit): # def __init__(self): # super(QtBoxStyleLineEdit6, self).__init__() # self.setMaxLength(1) # self.setFixedSize(50, 50) # self.setAlignment(Qt.AlignCenter) # self.setStyleSheet(""" # QLineEdit { # font-size: 25px; # border: 2px solid black; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELINEEDIT6_H # #define QTBOXSTYLELINEEDIT6_H # #include # class QtBoxStyleLineEdit6 : public QLineEdit # { # Q_OBJECT # public: # QtBoxStyleLineEdit6(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLELINEEDIT6_H # #include "qtboxstylelineedit6.h" # QtBoxStyleLineEdit6::QtBoxStyleLineEdit6(QWidget *parent) # : QLineEdit(parent) # { # setMaxLength(1); # setFixedSize(50, 50); # setAlignment(Qt::AlignCenter); # setStyleSheet(R"( # QLineEdit { # font-size: 25px; # border: 2px solid black; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/lineedit/style/demo7.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QLineEdit, QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QLineEdit = createWidgetMenuBase(QLineEdit) PATH_TO_IMG = str(Path(__file__).parent.parent.parent.parent / "res/images/camera.png").replace("\\", "/") class QtBoxStyleLineEdit7(QLineEdit): def __init__(self): super(QtBoxStyleLineEdit7, self).__init__(str(Path(__file__))) self.setAttribute(Qt.WA_MacShowFocusRect, False) self.setPlaceholderText("search") self.setFixedSize(185, 30) self.setStyleSheet(""" QLineEdit { border: 2px solid red; border-radius: 5px; padding-left: 5px; padding-right: 80px; } """) self.search_btn = QPushButton(self) self.search_btn.setText("Search") self.search_btn.setFixedSize(55, self.height()) self.search_btn.setCursor(Qt.PointingHandCursor) self.search_btn.move(self.width() - self.search_btn.width(), 0) self.search_btn.setStyleSheet(""" QPushButton { background-color: red; color: white; font-size: 13px; border-top: 2px solid red; border-right: 2px solid red; border-bottom: 2px solid red; border-top-right-radius: 5px; border-bottom-right-radius: 5px; } QPushButton:hover { background-color: #f31919; } QPushButton:pressed { background-color: #e21818; } """) self.camera_btn = QPushButton(self) self.camera_btn.setIcon(QIcon(PATH_TO_IMG)) self.camera_btn.setCursor(Qt.PointingHandCursor) self.camera_btn.setFixedSize(self.height(), self.height()) self.camera_btn.move(self.width()-self.search_btn.width()-self.camera_btn.width(), 0) self.camera_btn.setStyleSheet(""" QPushButton { border: none; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtGui import QIcon # from PySide2.QtWidgets import QLineEdit, QPushButton # class QtBoxStyleLineEdit7(QLineEdit): # def __init__(self): # super(QtBoxStyleLineEdit7, self).__init__() # self.setAttribute(Qt.WA_MacShowFocusRect, False) # self.setPlaceholderText("search") # self.setFixedSize(185, 30) # self.setStyleSheet(""" # QLineEdit { # border: 2px solid red; # border-radius: 5px; # padding-left: 5px; # padding-right: 80px; # } # """) # self.search_btn = QPushButton(self) # self.search_btn.setText("Search") # self.search_btn.setFixedSize(55, self.height()) # self.search_btn.setCursor(Qt.PointingHandCursor) # self.search_btn.move(self.width() - self.search_btn.width(), 0) # self.search_btn.setStyleSheet(""" # QPushButton { # background-color: red; # color: white; # font-size: 13px; # border-top: 2px solid red; # border-right: 2px solid red; # border-bottom: 2px solid red; # border-top-right-radius: 5px; # border-bottom-right-radius: 5px; # } # QPushButton:hover { # background-color: #f31919; # } # # QPushButton:pressed { # background-color: #e21818; # } # """) # self.camera_btn = QPushButton(self) # self.camera_btn.setIcon(QIcon(PATH_TO_IMG)) # self.camera_btn.setCursor(Qt.PointingHandCursor) # self.camera_btn.setFixedSize(self.height(), self.height()) # self.camera_btn.move(self.width()-self.search_btn.width()-self.camera_btn.width(), 0) # self.camera_btn.setStyleSheet(""" # QPushButton { # border: none; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELINEEDIT7_H # #define QTBOXSTYLELINEEDIT7_H # #include # #include # class QtBoxStyleLineEdit7 : public QLineEdit # { # Q_OBJECT # public: # QtBoxStyleLineEdit7(QWidget *parent = nullptr); # private: # QPushButton *searchBtn = new QPushButton(this); # QPushButton *cameraBtn = new QPushButton(this); # }; # #endif // QTBOXSTYLELINEEDIT7_H # #include "qtboxstylelineedit7.h" # #include # #include # QtBoxStyleLineEdit7::QtBoxStyleLineEdit7(QWidget *parent) # : QLineEdit(parent) # { # setAttribute(Qt::WA_MacShowFocusRect, false); # setPlaceholderText("search"); # setFixedSize(185, 30); # setStyleSheet(R"( # QLineEdit { # border: 2px solid red; # border-radius: 5px; # padding-left: 5px; # padding-right: 80px; # } # )"); # searchBtn->setText("Search"); # searchBtn->setFixedSize(55, height()); # searchBtn->setCursor(Qt::PointingHandCursor); # searchBtn->move(width()-searchBtn->width(), 0); # searchBtn->setStyleSheet(R"( # QPushButton { # background-color: red; # color: white; # font-size: 13px; # border-top: 2px solid red; # border-right: 2px solid red; # border-bottom: 2px solid red; # border-top-right-radius: 5px; # border-bottom-right-radius: 5px; # } # QPushButton:hover { # background-color: #f31919; # } # QPushButton:pressed { # background-color: #e21818; # } # )"); # cameraBtn->setIcon(QIcon(PATH_TO_IMG)); # cameraBtn->setCursor(Qt::PointingHandCursor); # cameraBtn->setFixedSize(height(), height()); # cameraBtn->move(width()-searchBtn->width()-cameraBtn->width(), 0); # cameraBtn->setStyleSheet("QPushButton {border:none;}"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/listwidget/__init__.py ================================================ from .func import demo1 from .style import demo1, demo2 ================================================ FILE: src/qtbox/demo/listwidget/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/listwidget/func/demo1.py ================================================ # PyQt from PyQt5.QtCore import QSize from PyQt5.QtWidgets import QListWidget, QListWidgetItem, QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QListWidget = createWidgetMenuBase(QListWidget) class QtBoxFuncListWidget1(QListWidget): def __init__(self): super(QtBoxFuncListWidget1, self).__init__(str(Path(__file__))) self.setFixedSize(100, 200) self.add_btns() def add_btns(self): for _ in range(5): item = QListWidgetItem() item.setSizeHint(QSize(80, 30)) self.addItem(item) btn = QPushButton() btn.setText("button") self.setItemWidget(item, btn) # PyQt # PySide # from PySide2.QtCore import QSize # from PySide2.QtWidgets import QListWidget, QListWidgetItem, QPushButton # class QtBoxFuncListWidget1(QListWidget): # def __init__(self): # super(QtBoxFuncListWidget1, self).__init__() # self.setFixedSize(80, 200) # self.add_btns() # def add_btns(self): # for _ in range(5): # item = QListWidgetItem() # item.setSizeHint(QSize(100, 30)) # self.addItem(item) # btn = QPushButton() # btn.setText("button") # self.setItemWidget(item, btn) # PySide # C++/Qt # #ifndef QTBOXFUNCLISTWIDGET1_H # #define QTBOXFUNCLISTWIDGET1_H # #include # class QtBoxFuncListWidget1 : public QListWidget # { # Q_OBJECT # public: # QtBoxFuncListWidget1(QWidget *parent = nullptr); # private: # void addBtns(); # }; # #endif // QTBOXFUNCLISTWIDGET1_H # #include "qtboxfunclistwidget1.h" # #include # #include # #include # QtBoxFuncListWidget1::QtBoxFuncListWidget1(QWidget *parent) # : QListWidget(parent) # { # setFixedSize(100, 200); # addBtns(); # } # void QtBoxFuncListWidget1::addBtns() # { # for(int i=0; i<5; i++) { # QListWidgetItem *item = new QListWidgetItem(); # item->setSizeHint(QSize(80, 30)); # addItem(item); # QPushButton *btn = new QPushButton(); # btn->setText("button"); # setItemWidget(item, btn); # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/listwidget/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/listwidget/style/demo1.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QListWidget, QListWidgetItem from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QListWidget = createWidgetMenuBase(QListWidget) class QtBoxStyleListWidget1(QListWidget): def __init__(self): super(QtBoxStyleListWidget1, self).__init__(str(Path(__file__))) self.setFixedSize(200, 200) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) for i in range(10): item = QListWidgetItem() item.setText(str(i)) self.addItem(item) self.setStyleSheet(""" QListView { border: none; background-color: #edeef3; } QListView::item { height: 40px; margin: 5px 5px 5px 5px; background-color: white; border-radius: 6px; } QListView::item:hover{ background-color: whitesmoke; } QListView::item:selected{ color: black; border: 1px solid lightgray; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QListWidget, QListWidgetItem # class QtBoxStyleListWidget1(QListWidget): # def __init__(self): # super(QtBoxStyleListWidget1, self).__init__(str(Path(__file__))) # self.setFixedSize(200, 200) # self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) # self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) # for i in range(10): # item = QListWidgetItem() # item.setText(str(i)) # self.addItem(item) # self.setStyleSheet(""" # QListView { # border: none; # background-color: #edeef3; # } # QListView::item { # height: 40px; # margin: 5px 5px 5px 5px; # background-color: white; # border-radius: 6px; # } # QListView::item:hover{ # background-color: whitesmoke; # } # QListView::item:selected{ # color: black; # border: 1px solid lightgray; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELISTWIDGET1_H # #define QTBOXSTYLELISTWIDGET1_H # #include # class QtBoxStyleListWidget1 : public QListWidget # { # Q_OBJECT # public: # QtBoxStyleListWidget1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLELISTWIDGET1_H # #include "qtboxstylelistwidget1.h" # #include # #include # QtBoxStyleListWidget1::QtBoxStyleListWidget1(QWidget *parent) # : QListWidget(parent) # { # setFixedSize(200, 200); # setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); # setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); # for(int i=0; i<10; i++) { # QListWidgetItem *item = new QListWidgetItem(); # item->setText(QString("%1").arg(i)); # addItem(item); # } # setStyleSheet(R"( # QListView { # border: none; # background-color: #edeef3; # } # QListView::item { # height: 40px; # margin: 5px 5px 5px 5px; # background-color: white; # border-radius: 6px; # } # QListView::item:hover{ # background-color: whitesmoke; # } # QListView::item:selected{ # color: black; # border: 1px solid lightgray; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/listwidget/style/demo2.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QListWidget, QListWidgetItem from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QListWidget = createWidgetMenuBase(QListWidget) class QtBoxStyleListWidget2(QListWidget): def __init__(self): super(QtBoxStyleListWidget2, self).__init__(str(Path(__file__))) self.setFixedSize(200, 200) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) for i in range(10): item = QListWidgetItem() item.setText(str(i)) self.addItem(item) self.setStyleSheet(""" QListView { border: none; background-color: #65afdc; font-weight: bold; } QListView::item { height: 40px; color: white; border-bottom: 1px solid #8fcef4; } QListView::item:hover:!selected{ background-color: #8fcef4; padding-left: 5px; padding-bottom: 2px; } QListView::item:selected{ background-color: #5da0c7; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QListWidget, QListWidgetItem # class QtBoxStyleListWidget2(QListWidget): # def __init__(self): # super(QtBoxStyleListWidget2, self).__init__() # self.setFixedSize(200, 200) # self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) # self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) # for i in range(10): # item = QListWidgetItem() # item.setText(str(i)) # self.addItem(item) # self.setStyleSheet(""" # QListView { # border: none; # background-color: #65afdc; # font-weight: bold; # } # QListView::item { # height: 40px; # color: white; # border-bottom: 1px solid #8fcef4; # } # QListView::item:hover:!selected{ # background-color: #8fcef4; # padding-left: 5px; # padding-bottom: 2px; # } # QListView::item:selected{ # background-color: #5da0c7; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLELISTWIDGET2_H # #define QTBOXSTYLELISTWIDGET2_H # #include # class QtBoxStyleListWidget2 : public QListWidget # { # Q_OBJECT # public: # QtBoxStyleListWidget2(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLELISTWIDGET2_H # #include "qtboxstylelistwidget2.h" # #include # #include # QtBoxStyleListWidget2::QtBoxStyleListWidget2(QWidget *parent) # : QListWidget(parent) # { # setFixedSize(200, 200); # setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); # setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); # for(int i=0; i<10; i++) { # QListWidgetItem *item = new QListWidgetItem(); # item->setText(QString("%1").arg(i)); # addItem(item); # } # setStyleSheet(R"( # QListView { # border: none; # background-color: #65afdc; # font-weight: bold; # } # QListView::item { # height: 40px; # color: white; # border-bottom: 1px solid #8fcef4; # } # QListView::item:hover:!selected{ # background-color: #8fcef4; # padding-left: 5px; # padding-bottom: 2px; # } # QListView::item:selected{ # background-color: #5da0c7; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/__init__.py ================================================ from .func import demo1, demo2 from .style import demo1, demo2, demo3, demo4, demo5, demo6, demo7, demo8, demo9 ================================================ FILE: src/qtbox/demo/progressbar/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/progressbar/func/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QProgressBar from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxFuncProgressBar1(QProgressBar): def __init__(self): super(QtBoxFuncProgressBar1, self).__init__(str(Path(__file__))) self.setRange(0, 0) # PyQt # PySide # from PySide2.QtWidgets import QProgressBar # class QtBoxFuncProgressBar1(QProgressBar): # def __init__(self): # super(QtBoxFuncProgressBar1, self).__init__() # self.setRange(0, 0) # PySide # C++/Qt # #ifndef QTBOXFUNCPROGRESSBAR1_H # #define QTBOXFUNCPROGRESSBAR1_H # #include # class QtBoxFuncProgressBar1 : public QProgressBar # { # Q_OBJECT # public: # QtBoxFuncProgressBar1(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCPROGRESSBAR1_H # #include "qtboxfuncprogressbar1.h" # QtBoxFuncProgressBar1::QtBoxFuncProgressBar1(QWidget *parent) # : QProgressBar(parent) # { # setRange(0, 0); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/func/demo2.py ================================================ # PyQt from PyQt5.QtWidgets import QProgressBar from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxFuncProgressBar2(QProgressBar): def __init__(self): super(QtBoxFuncProgressBar2, self).__init__(str(Path(__file__))) self.setInvertedAppearance(True) self.setRange(0, 100) self.setValue(80) # PyQt # PySide # from PySide2.QtWidgets import QProgressBar # class QtBoxFuncProgressBar2(QProgressBar): # def __init__(self): # super(QtBoxFuncProgressBar2, self).__init__() # self.setInvertedAppearance(True) # self.setRange(0, 100) # self.setValue(80) # PySide # C++/Qt # #ifndef QTBOXFUNCPROGRESSBAR2_H # #define QTBOXFUNCPROGRESSBAR2_H # #include # class QtBoxFuncProgressBar2 : public QProgressBar # { # Q_OBJECT # public: # QtBoxFuncProgressBar2(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCPROGRESSBAR2_H # #include "qtboxfuncprogressbar2.h" # QtBoxFuncProgressBar2::QtBoxFuncProgressBar2(QWidget *parent) # : QProgressBar(parent) # { # setInvertedAppearance(true); # setRange(0, 100); # setValue(80); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/progressbar/style/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QProgressBar from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxStyleProgressBar1(QProgressBar): def __init__(self): super(QtBoxStyleProgressBar1, self).__init__(str(Path(__file__))) self.setFormat("loading...") self.setRange(0, 100) self.setValue(80) self.setStyleSheet(""" QProgressBar { border: 2px solid lightgray; border-radius: 5px; text-align: center; color: white; } QProgressBar::chunk { background-color: #cd96cd; border-radius: 4px; } """) # PyQt # PySide # from PySide2.QtWidgets import QProgressBar # class QtBoxStyleProgressBar1(QProgressBar): # def __init__(self): # super(QtBoxStyleProgressBar1, self).__init__() # self.setFormat("loading...") # self.setRange(0, 100) # self.setValue(80) # self.setStyleSheet(""" # QProgressBar { # border: 2px solid lightgray; # border-radius: 5px; # text-align: center; # color: white; # } # QProgressBar::chunk { # background-color: #cd96cd; # border-radius: 4px; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPROGRESSBAR1_H # #define QTBOXSTYLEPROGRESSBAR1_H # #include # class QtBoxStyleProgressBar1 : public QProgressBar # { # Q_OBJECT # public: # QtBoxStyleProgressBar1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPROGRESSBAR1_H # #include "qtboxstyleprogressbar1.h" # QtBoxStyleProgressBar1::QtBoxStyleProgressBar1(QWidget *parent) # : QProgressBar(parent) # { # setFormat("loading..."); # setRange(0, 100); # setValue(80); # setStyleSheet(R"( # QProgressBar { # border: 2px solid lightgray; # border-radius: 5px; # text-align: center; # color: white; # } # QProgressBar::chunk { # background-color: #cd96cd; # border-radius: 4px; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/style/demo2.py ================================================ # PyQt from PyQt5.QtWidgets import QProgressBar from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxStyleProgressBar2(QProgressBar): def __init__(self): super(QtBoxStyleProgressBar2, self).__init__(str(Path(__file__))) self.setTextVisible(False) self.setRange(0, 100) self.setValue(80) self.setStyleSheet(""" QProgressBar { border: 2px solid #888783; border-radius: 5px; } QProgressBar::chunk { background-color: #74d65f; border-radius: 2px; width: 9px; margin: 0.5px; } """) # PyQt # PySide # from PySide2.QtWidgets import QProgressBar # class QtBoxStyleProgressBar2(QProgressBar): # def __init__(self): # super(QtBoxStyleProgressBar2, self).__init__() # self.setTextVisible(False) # self.setRange(0, 100) # self.setValue(80) # self.setStyleSheet(""" # QProgressBar { # border: 2px solid #888783; # border-radius: 5px; # } # QProgressBar::chunk { # background-color: #74d65f; # border-radius: 2px; # width: 9px; # margin: 0.5px; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPROGRESSBAR2_H # #define QTBOXSTYLEPROGRESSBAR2_H # #include # class QtBoxStyleProgressBar2 : public QProgressBar # { # Q_OBJECT # public: # QtBoxStyleProgressBar2(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPROGRESSBAR2_H # #include "qtboxstyleprogressbar2.h" # QtBoxStyleProgressBar2::QtBoxStyleProgressBar2(QWidget *parent) # : QProgressBar(parent) # { # setTextVisible(false); # setRange(0, 100); # setValue(80); # setStyleSheet(R"( # QProgressBar { # border: 2px solid #888783; # border-radius: 5px; # } # QProgressBar::chunk { # background-color: #74d65f; # border-radius: 2px; # width: 9px; # margin: 0.5px; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/style/demo3.py ================================================ # PyQt from PyQt5.QtWidgets import QProgressBar from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxStyleProgressBar3(QProgressBar): def __init__(self): super(QtBoxStyleProgressBar3, self).__init__(str(Path(__file__))) self.setRange(0, 100) self.setValue(80) self.setStyleSheet(""" QProgressBar { border: 2px solid white; background-color: black; padding-left: 2px; padding-right: 2px; text-align: center; } QProgressBar::chunk { background-color: white; margin-top: 2px; margin-bottom: 2px; } """) # PyQt # PySide # from PySide2.QtWidgets import QProgressBar # class QtBoxStyleProgressBar3(QProgressBar): # def __init__(self): # super(QtBoxStyleProgressBar3, self).__init__() # self.setRange(0, 100) # self.setValue(80) # self.setStyleSheet(""" # QProgressBar { # border: 2px solid white; # background-color: black; # padding-left: 2px; # padding-right: 2px; # text-align: center; # } # QProgressBar::chunk { # background-color: white; # margin-top: 2px; # margin-bottom: 2px; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPROGRESSBAR3_H # #define QTBOXSTYLEPROGRESSBAR3_H # #include # class QtBoxStyleProgressBar3 : public QProgressBar # { # Q_OBJECT # public: # QtBoxStyleProgressBar3(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPROGRESSBAR3_H # #include "qtboxstyleprogressbar3.h" # QtBoxStyleProgressBar3::QtBoxStyleProgressBar3(QWidget *parent) # : QProgressBar(parent) # { # setRange(0, 100); # setValue(80); # setStyleSheet(R"( # QProgressBar { # border: 2px solid white; # background-color: black; # padding-left: 2px; # padding-right: 2px; # text-align: center; # } # QProgressBar::chunk { # background-color: white; # margin-top: 2px; # margin-bottom: 2px; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/style/demo4.py ================================================ # PyQt from PyQt5.QtGui import QColor from PyQt5.QtWidgets import QProgressBar, QGraphicsDropShadowEffect from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxStyleProgressBar4(QProgressBar): def __init__(self): super(QtBoxStyleProgressBar4, self).__init__(str(Path(__file__))) self.setTextVisible(False) self.setMaximumHeight(10) self.setRange(0, 100) self.setValue(80) self.setStyleSheet(""" QProgressBar { border: 1px solid lightgray; background-color: #2b241c; border-radius: 5px; } QProgressBar::chunk { background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #f9dc98, stop:1 #f4b543); border-radius: 4px; } """) self.add_shadow() def add_shadow(self): shadow = QGraphicsDropShadowEffect(self) shadow.setBlurRadius(40) shadow.setOffset(0, 0) shadow.setColor(QColor(241, 177, 66)) self.setGraphicsEffect(shadow) # PyQt # PySide # from PySide2.QtGui import QColor # from PySide2.QtWidgets import QProgressBar, QGraphicsDropShadowEffect # class QtBoxStyleProgressBar4(QProgressBar): # def __init__(self): # super(QtBoxStyleProgressBar4, self).__init__() # self.setTextVisible(False) # self.setMaximumHeight(10) # self.setRange(0, 100) # self.setValue(80) # self.setStyleSheet(""" # QProgressBar { # border: 1px solid lightgray; # background-color: #2b241c; # border-radius: 5px; # } # QProgressBar::chunk { # background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #f9dc98, stop:1 #f4b543); # border-radius: 4px; # } # """) # self.add_shadow() # def add_shadow(self): # shadow = QGraphicsDropShadowEffect(self) # shadow.setBlurRadius(40) # shadow.setOffset(0, 0) # shadow.setColor(QColor(241, 177, 66)) # self.setGraphicsEffect(shadow) # PySide # C++/Qt # #ifndef QTBOXSTYLEPROGRESSBAR4_H # #define QTBOXSTYLEPROGRESSBAR4_H # #include # class QtBoxStyleProgressBar4 : public QProgressBar # { # Q_OBJECT # public: # QtBoxStyleProgressBar4(QWidget *parent = nullptr); # private: # void addShadow(); # }; # #endif // QTBOXSTYLEPROGRESSBAR4_H # #include "qtboxstyleprogressbar4.h" # #include # #include # QtBoxStyleProgressBar4::QtBoxStyleProgressBar4(QWidget *parent) # : QProgressBar(parent) # { # setTextVisible(false); # setMaximumHeight(10); # setRange(0, 100); # setValue(80); # setStyleSheet(R"( # QProgressBar { # border: 1px solid lightgray; # background-color: #2b241c; # border-radius: 5px; # } # QProgressBar::chunk { # background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #f9dc98, stop:1 #f4b543); # border-radius: 4px; # } # )"); # addShadow(); # } # void QtBoxStyleProgressBar4::addShadow() # { # QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); # shadow->setBlurRadius(40); # shadow->setOffset(0, 0); # shadow->setColor(QColor(241, 177, 66)); # setGraphicsEffect(shadow); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/style/demo5.py ================================================ # PyQt from PyQt5.QtWidgets import QProgressBar from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxStyleProgressBar5(QProgressBar): def __init__(self): super(QtBoxStyleProgressBar5, self).__init__(str(Path(__file__))) self.setTextVisible(False) self.setRange(0, 100) self.setValue(80) self.setStyleSheet(""" QProgressBar { border: 1px solid lightgray; border-radius: 3px; background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.4, stop:0 white, stop:1 #dedede); } QProgressBar::chunk { background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.4, stop:0 white, stop:1 #64d651); border-radius: 2px; } """) # PyQt # PySide # from PySide2.QtWidgets import QProgressBar # class QtBoxStyleProgressBar5(QProgressBar): # def __init__(self): # super(QtBoxStyleProgressBar5, self).__init__() # self.setTextVisible(False) # self.setRange(0, 100) # self.setValue(80) # self.setStyleSheet(""" # QProgressBar { # border: 1px solid lightgray; # border-radius: 3px; # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.4, stop:0 white, stop:1 #dedede); # } # QProgressBar::chunk { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.4, stop:0 white, stop:1 #64d651); # border-radius: 2px; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPROGRESSBAR5_H # #define QTBOXSTYLEPROGRESSBAR5_H # #include # class QtBoxStyleProgressBar5 : public QProgressBar # { # Q_OBJECT # public: # QtBoxStyleProgressBar5(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPROGRESSBAR5_H # #include "qtboxstyleprogressbar5.h" # QtBoxStyleProgressBar5::QtBoxStyleProgressBar5(QWidget *parent) # : QProgressBar(parent) # { # setTextVisible(false); # setRange(0, 100); # setValue(80); # setStyleSheet(R"( # QProgressBar { # border: 1px solid lightgray; # border-radius: 3px; # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.4, stop:0 white, stop:1 #dedede); # } # QProgressBar::chunk { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.4, stop:0 white, stop:1 #64d651); # border-radius: 2px; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/style/demo6.py ================================================ # PyQt from PyQt5.QtWidgets import QProgressBar from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxStyleProgressBar6(QProgressBar): def __init__(self): super(QtBoxStyleProgressBar6, self).__init__(str(Path(__file__))) self.setTextVisible(False) self.setRange(0, 100) self.setValue(80) self.setStyleSheet(""" QProgressBar { background-color: #c2c6c9; border: 2px solid #b0b4b7; border-right: 2px solid #d5d8dd; border-bottom: 2px solid #d5d8dd; border-radius: 2px; } QProgressBar::chunk { background-color: #0c107b; border-radius: 1px; width: 9px; margin: 0.5px; } """) # PyQt # PySide # from PySide2.QtWidgets import QProgressBar # class QtBoxStyleProgressBar6(QProgressBar): # def __init__(self): # super(QtBoxStyleProgressBar6, self).__init__() # self.setTextVisible(False) # self.setRange(0, 100) # self.setValue(80) # self.setStyleSheet(""" # QProgressBar { # background-color: #c2c6c9; # border: 2px solid #b0b4b7; # border-right: 2px solid #d5d8dd; # border-bottom: 2px solid #d5d8dd; # border-radius: 2px; # } # QProgressBar::chunk { # background-color: #0c107b; # border-radius: 1px; # width: 9px; # margin: 0.5px; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPROGRESSBAR6_H # #define QTBOXSTYLEPROGRESSBAR6_H # #include # class QtBoxStyleProgressBar6 : public QProgressBar # { # Q_OBJECT # public: # QtBoxStyleProgressBar6(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPROGRESSBAR6_H # #include "qtboxstyleprogressbar6.h" # QtBoxStyleProgressBar6::QtBoxStyleProgressBar6(QWidget *parent) # : QProgressBar(parent) # { # setTextVisible(false); # setRange(0, 100); # setValue(80); # setStyleSheet(R"( # QProgressBar { # background-color: #c2c6c9; # border: 2px solid #b0b4b7; # border-right: 2px solid #d5d8dd; # border-bottom: 2px solid #d5d8dd; # border-radius: 2px; # } # QProgressBar::chunk { # background-color: #0c107b; # border-radius: 1px; # width: 9px; # margin: 0.5px; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/style/demo7.py ================================================ # PyQt from PyQt5.QtCore import Qt, QRectF from PyQt5.QtWidgets import QProgressBar from PyQt5.QtGui import QPainter, QColor, QPen, QFont, QFontMetricsF from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxStyleProgressBar7(QProgressBar): def __init__(self): super(QtBoxStyleProgressBar7, self).__init__(str(Path(__file__))) self.setFixedSize(80, 80) self.setRange(0, 100) self.setValue(80) def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) offset = 20 arc_rect = QRectF(self.rect().left() + offset / 2, self.rect().top() + offset / 2, self.rect().width() - offset, self.rect().height() - offset) arc_pen = QPen() arc_pen.setColor(QColor(127, 106, 209)) arc_pen.setWidth(18) painter.setPen(arc_pen) percent = self.value() / self.maximum() if self.maximum() != 0 else 0 painter.drawArc(arc_rect, 90*16, int(percent*360*16)) font = QFont() font.setPixelSize(15) painter.setFont(font) font_metrics = QFontMetricsF(font) text_width = font_metrics.width(self.text()) painter.drawText(int(self.width()/2-text_width/2), 45, self.text()) # PyQt # PySide # from PySide2.QtCore import Qt, QRectF # from PySide2.QtWidgets import QProgressBar # from PySide2.QtGui import QPainter, QColor, QPen, QFont, QFontMetricsF # class QtBoxStyleProgressBar7(QProgressBar): # def __init__(self): # super(QtBoxStyleProgressBar7, self).__init__() # self.setFixedSize(80, 80) # self.setRange(0, 100) # self.setValue(80) # def paintEvent(self, event): # painter = QPainter(self) # painter.setRenderHint(QPainter.Antialiasing) # offset = 20 # arc_rect = QRectF(self.rect().left() + offset / 2, self.rect().top() + offset / 2, self.rect().width() - offset, self.rect().height() - offset) # arc_pen = QPen() # arc_pen.setColor(QColor(127, 106, 209)) # arc_pen.setWidth(18) # painter.setPen(arc_pen) # percent = self.value() / self.maximum() if self.maximum() != 0 else 0 # painter.drawArc(arc_rect, 90*16, int(percent*360*16)) # font = QFont() # font.setPixelSize(15) # painter.setFont(font) # font_metrics = QFontMetricsF(font) # text_width = font_metrics.width(self.text()) # painter.drawText(int(self.width()/2-text_width/2), 45, self.text()) # PySide # C++/Qt # #ifndef QTBOXSTYLEPROGRESSBAR7_H # #define QTBOXSTYLEPROGRESSBAR7_H # #include # #include # class QtBoxStyleProgressBar7 : public QProgressBar # { # Q_OBJECT # protected: # void paintEvent(QPaintEvent *event); # public: # QtBoxStyleProgressBar7(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPROGRESSBAR7_H #include "qtboxstyleprogressbar7.h" #include #include #include #include #include #include # QtBoxStyleProgressBar7::QtBoxStyleProgressBar7(QWidget *parent) # : QProgressBar(parent) # { # setFixedSize(80, 80); # setRange(0, 100); # setValue(80); # } # void QtBoxStyleProgressBar7::paintEvent(QPaintEvent *event) # { # QPainter painter(this); # painter.setRenderHint(QPainter::Antialiasing); # int offset = 20; # QRectF arcRect = QRectF(rect().left()+offset/2, rect().top()+offset/2, rect().width()-offset, rect().height()-offset); # QPen arcPen = QPen(); # arcPen.setColor(QColor(127, 106, 209)); # arcPen.setWidth(18); # painter.setPen(arcPen); # float percent = 0.0; # if (maximum() != 0) { # percent = float(value()) / float(maximum()); # } # painter.drawArc(arcRect, 90*16, int(percent*360*16)); # QFont font = QFont(); # font.setPixelSize(15); # painter.setFont(font); # QFontMetricsF fontMetricsF = QFontMetricsF(font); # float textWidth = fontMetricsF.size(Qt::TextSingleLine, text()).width(); # painter.drawText(int(width()/2-textWidth/2), 45, text()); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/style/demo8.py ================================================ # PyQt from PyQt5.QtCore import Qt, QRectF from PyQt5.QtWidgets import QProgressBar from PyQt5.QtGui import QPainter, QColor, QPen, QFont, QFontMetricsF from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxStyleProgressBar8(QProgressBar): def __init__(self): super(QtBoxStyleProgressBar8, self).__init__(str(Path(__file__))) self.setFixedSize(80, 80) self.setRange(0, 100) self.setValue(80) def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.setPen(Qt.NoPen) painter.setBrush(QColor(33, 33, 33)) painter.drawEllipse(self.rect()) offset = 4 arc_rect = QRectF(self.rect().left() + offset / 2, self.rect().top() + offset / 2, self.rect().width() - offset, self.rect().height() - offset) arc_pen = QPen() arc_pen.setColor(QColor(57, 57, 57)) arc_pen.setWidth(4) painter.setPen(arc_pen) painter.drawArc(arc_rect, 90*16, 360*16) arc_pen.setColor(QColor(241, 150, 76)) painter.setPen(arc_pen) percent = self.value() / self.maximum() if self.maximum() != 0 else 0 painter.drawArc(arc_rect, 90*16, int(percent*360*16)) font = QFont() font.setPixelSize(18) painter.setFont(font) font_metrics = QFontMetricsF(font) text_width = font_metrics.width(self.text()) painter.drawText(int(self.width()/2-text_width/2), 45, self.text()) # PyQt # PySide # from PySide2.QtCore import Qt, QRectF # from PySide2.QtWidgets import QProgressBar # from PySide2.QtGui import QPainter, QColor, QPen, QFont, QFontMetricsF # class QtBoxStyleProgressBar8(QProgressBar): # def __init__(self): # super(QtBoxStyleProgressBar8, self).__init__() # self.setFixedSize(80, 80) # self.setRange(0, 100) # self.setValue(80) # def paintEvent(self, event): # painter = QPainter(self) # painter.setRenderHint(QPainter.Antialiasing) # painter.setPen(Qt.NoPen) # painter.setBrush(QColor(33, 33, 33)) # painter.drawEllipse(self.rect()) # offset = 4 # arc_rect = QRectF(self.rect().left() + offset / 2, self.rect().top() + offset / 2, self.rect().width() - offset, self.rect().height() - offset) # arc_pen = QPen() # arc_pen.setColor(QColor(57, 57, 57)) # arc_pen.setWidth(4) # painter.setPen(arc_pen) # painter.drawArc(arc_rect, 90*16, 360*16) # arc_pen.setColor(QColor(241, 150, 76)) # painter.setPen(arc_pen) # percent = self.value() / self.maximum() if self.maximum() != 0 else 0 # painter.drawArc(arc_rect, 90*16, int(percent*360*16)) # font = QFont() # font.setPixelSize(18) # painter.setFont(font) # font_metrics = QFontMetricsF(font) # text_width = font_metrics.width(self.text()) # painter.drawText(int(self.width()/2-text_width/2), 45, self.text()) # PySide # C++/Qt # #ifndef QTBOXSTYLEPROGRESSBAR8_H # #define QTBOXSTYLEPROGRESSBAR8_H # #include # #include # class QtBoxStyleProgressBar8 : public QProgressBar # { # Q_OBJECT # protected: # void paintEvent(QPaintEvent *event); # public: # QtBoxStyleProgressBar8(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPROGRESSBAR8_H # #include "qtboxstyleprogressbar8.h" # #include # #include # #include # #include # #include # #include # #include # QtBoxStyleProgressBar8::QtBoxStyleProgressBar8(QWidget *parent) # : QProgressBar(parent) # { # setFixedSize(80, 80); # setRange(0, 100); # setValue(80); # } # void QtBoxStyleProgressBar8::paintEvent(QPaintEvent *event) # { # QPainter painter(this); # painter.setRenderHint(QPainter::Antialiasing); # painter.setPen(Qt::NoPen); # painter.setBrush(QColor(33, 33, 33)); # painter.drawEllipse(rect()); # int offset = 4; # QRectF arcRect = QRectF(rect().left()+offset/2, rect().top()+offset/2, rect().width()-offset, rect().height()-offset); # QPen arcPen = QPen(); # arcPen.setColor(QColor(57, 57, 57)); # arcPen.setWidth(4); # painter.setPen(arcPen); # painter.drawArc(arcRect, 90*16, 360*16); # arcPen.setColor(QColor(241, 150, 76)); # painter.setPen(arcPen); # float percent = 0.0; # if (maximum() != 0) { # percent = float(value()) / float(maximum()); # } # painter.drawArc(arcRect, 90*16, int(percent*360*16)); # QFont font = QFont(); # font.setPixelSize(18); # painter.setFont(font); # QFontMetricsF fontMetricsF = QFontMetricsF(font); # float textWidth = fontMetricsF.size(Qt::TextSingleLine, text()).width(); # painter.drawText(int(width()/2-textWidth/2), 45, text()); # } # C++/Qt ================================================ FILE: src/qtbox/demo/progressbar/style/demo9.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QProgressBar from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QProgressBar = createWidgetMenuBase(QProgressBar) class QtBoxStyleProgressBar9(QProgressBar): def __init__(self): super(QtBoxStyleProgressBar9, self).__init__(str(Path(__file__))) self.setOrientation(Qt.Vertical) self.setTextVisible(False) self.setMaximumWidth(10) self.setRange(0, 100) self.setValue(80) self.setStyleSheet(""" QProgressBar { border: 2px solid black; background-color: #f8f8f8; border-radius: 5px; padding-left: 2px; padding-right: 2px; } QProgressBar::chunk { background-color: #d33124; border-radius: 4px; margin-top: 2px; margin-bottom: 2px; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QProgressBar # class QtBoxStyleProgressBar9(QProgressBar): # def __init__(self): # super(QtBoxStyleProgressBar9, self).__init__() # self.setOrientation(Qt.Vertical) # self.setTextVisible(False) # self.setMaximumWidth(10) # self.setRange(0, 100) # self.setValue(80) # self.setStyleSheet(""" # QProgressBar { # border: 2px solid black; # background-color: #f8f8f8; # border-radius: 5px; # padding-left: 2px; # padding-right: 2px; # } # QProgressBar::chunk { # background-color: #d33124; # border-radius: 4px; # margin-top: 2px; # margin-bottom: 2px; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPROGRESSBAR9_H # #define QTBOXSTYLEPROGRESSBAR9_H # #include # class QtBoxStyleProgressBar9 : public QProgressBar # { # Q_OBJECT # public: # QtBoxStyleProgressBar9(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPROGRESSBAR9_H # #include "qtboxstyleprogressbar9.h" # #include # QtBoxStyleProgressBar9::QtBoxStyleProgressBar9(QWidget *parent) # : QProgressBar(parent) # { # setOrientation(Qt::Vertical); # setTextVisible(false); # setMaximumWidth(10); # setRange(0, 100); # setValue(80); # setStyleSheet(R"( # QProgressBar { # border: 2px solid black; # background-color: #f8f8f8; # border-radius: 5px; # padding-left: 2px; # padding-right: 2px; # } # QProgressBar::chunk { # background-color: #d33124; # border-radius: 4px; # margin-top: 2px; # margin-bottom: 2px; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/__init__.py ================================================ from .func import demo1, demo2, demo3 from .style import demo1, demo2, demo3, demo4, demo5, demo6, demo7, demo8, demo9, demo10, demo11, demo12 ================================================ FILE: src/qtbox/demo/pushbutton/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/pushbutton/func/demo1.py ================================================ # PyQt from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtWidgets import QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxFuncButton1(QPushButton): def __init__(self): super(QtBoxFuncButton1, self).__init__(str(Path(__file__))) self.setText("Send SMS") self.clicked.connect(self.start_SMS_thread) self.SMS_thread = SMSThread() self.SMS_thread.count_signal.connect(self.count_down) self.SMS_thread.finished_signal.connect(self.restore) def start_SMS_thread(self): self.SMS_thread.start() def count_down(self, count): self.setEnabled(False) self.setText(f"Resend ({count})") def restore(self): self.setEnabled(True) self.setText("Send SMS") class SMSThread(QThread): count_signal = pyqtSignal(int) finished_signal = pyqtSignal() def __init__(self): super(SMSThread, self).__init__() def run(self): self.send_SMS() count = 60 while count >= 1: self.count_signal.emit(count) count -= 1 self.sleep(1) self.finished_signal.emit() def send_SMS(self): """send verification code to the user here""" ... # PyQt # PySide # from PySide2.QtCore import QThread, Signal # from PySide2.QtWidgets import QPushButton # class QtBoxFuncButton1(QPushButton): # def __init__(self): # super(QtBoxFuncButton1, self).__init__() # self.setText("Send SMS") # self.clicked.connect(self.start_SMS_thread) # self.SMS_thread = SMSThread() # self.SMS_thread.count_signal.connect(self.count_down) # self.SMS_thread.finished_signal.connect(self.restore) # def start_SMS_thread(self): # self.SMS_thread.start() # def count_down(self, count): # self.setEnabled(False) # self.setText(f"Resend ({count})") # def restore(self): # self.setEnabled(True) # self.setText("Send SMS") # class SMSThread(QThread): # count_signal = Signal(int) # finished_signal = Signal() # def __init__(self): # super(SMSThread, self).__init__() # def run(self): # self.send_SMS() # count = 60 # while count >= 1: # self.count_signal.emit(count) # count -= 1 # self.sleep(1) # self.finished_signal.emit() # def send_SMS(self): # """send verification code to the user here""" # ... # PySide # C++/Qt # #ifndef QTBOXFUNCPUSHBUTTON1_H # #define QTBOXFUNCPUSHBUTTON1_H # #include "smsthread.h" # #include # class QtBoxFuncPushButton1 : public QPushButton # { # Q_OBJECT # public: # QtBoxFuncPushButton1(QWidget *parent = nullptr); # private: # SMSThread *smsThread = new SMSThread(); # private slots: # void startSMSThread(); # void countDown(int count); # void restore(); # }; # #endif // QTBOXFUNCPUSHBUTTON1_H # #ifndef SMSTHREAD_H # #define SMSTHREAD_H # #include # class SMSThread : public QThread # { # Q_OBJECT # public: # SMSThread(); # protected: # void run(); # private: # int count; # void sendSMS(); # signals: # void countSignal(int count); # void finishedSignal(); # }; # #endif // SMSTHREAD_H # #include "qtboxfuncpushbutton1.h" # #include # QtBoxFuncPushButton1::QtBoxFuncPushButton1(QWidget *parent) # : QPushButton(parent) # { # setText("Send SMS"); # connect(this, SIGNAL(clicked()), this, SLOT(startSMSThread())); # connect(smsThread, SIGNAL(countSignal(int)), this, SLOT(countDown(int))); # connect(smsThread, SIGNAL(finishedSignal()), this, SLOT(restore())); # } # void QtBoxFuncPushButton1::startSMSThread() # { # smsThread->start(); # } # void QtBoxFuncPushButton1::countDown(int count) # { # setEnabled(false); # setText(QString("Resend %1").arg(QString::number(count))); # } # void QtBoxFuncPushButton1::restore() # { # setEnabled(true); # setText("Send SMS"); # } # #include "smsthread.h" # SMSThread::SMSThread() # { # } # void SMSThread::run() # { # sendSMS(); # count = 60; # while (count >= 1){ # emit countSignal(count); # count -= 1; # sleep(1); # } # emit finishedSignal(); # } # void SMSThread::sendSMS() # { # // send verification code to the user here # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/func/demo2.py ================================================ # PyQt from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtWidgets import QPushButton, QMessageBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxFuncButton2(QPushButton): def __init__(self): super(QtBoxFuncButton2, self).__init__(str(Path(__file__))) self.setText("Login") self.clicked.connect(self.start_verify_thread) self.verify_thread = VerifyThread() self.verify_thread.verify_signal.connect(self.do_after_verification) def start_verify_thread(self): self.verify_thread.start() def do_after_verification(self, verify_result): if not verify_result: self.verify_not_ok() else: self.verify_ok() def verify_not_ok(self): QMessageBox.critical(self, "Verify", "Wrong username or password") def verify_ok(self): QMessageBox.information(self, "Verify", "Login successfully") class VerifyThread(QThread): verify_signal = pyqtSignal(bool) def __init__(self): super(VerifyThread, self).__init__() def run(self): self.verify_signal.emit(self.verify()) def verify(self): """ verify username and password here :return: True or False """ ... return False # PyQt # PySide # from PySide2.QtCore import QThread, Signal # from PySide2.QtWidgets import QPushButton, QMessageBox # class QtBoxFuncButton2(QPushButton): # def __init__(self): # super(QtBoxFuncButton2, self).__init__() # self.setText("Login") # self.clicked.connect(self.start_verify_thread) # self.verify_thread = VerifyThread() # self.verify_thread.verify_signal.connect(self.do_after_verification) # def start_verify_thread(self): # self.verify_thread.start() # def do_after_verification(self, verify_result): # if not verify_result: # self.verify_not_ok() # else: # self.verify_ok() # def verify_not_ok(self): # QMessageBox.critical(self, "Verify", "Wrong username or password") # def verify_ok(self): # QMessageBox.information(self, "Verify", "Login successfully") # class VerifyThread(QThread): # verify_signal = Signal(bool) # def __init__(self): # super(VerifyThread, self).__init__() # def run(self): # self.verify_signal.emit(self.verify()) # def verify(self): # """ # verify username and password here # :return: True or False # """ # ... # return False # PySide # C++/Qt # #ifndef QTBOXFUNCPUSHBUTTON2_H # #define QTBOXFUNCPUSHBUTTON2_H # #include "verifythread.h" # #include # class QtBoxFuncPushButton2 : public QPushButton # { # Q_OBJECT # public: # QtBoxFuncPushButton2(QWidget *parent = nullptr); # private: # VerifyThread *verifyThread = new VerifyThread(); # private slots: # void startVerifyThread(); # void doAfterVerification(bool verifyResult); # void verifyNotOk(); # void verifyOk(); # }; # #endif // QTBOXFUNCPUSHBUTTON2_H # #ifndef VERIFYTHREAD_H # #define VERIFYTHREAD_H # #include # class VerifyThread : public QThread # { # Q_OBJECT # public: # VerifyThread(); # protected: # void run(); # private: # bool verify(); # signals: # void verifySignal(bool verifyResult); # }; # #endif // VERIFYTHREAD_H # #include "qtboxfuncpushbutton2.h" # #include # QtBoxFuncPushButton2::QtBoxFuncPushButton2(QWidget *parent) # : QPushButton(parent) # { # setText("Login"); # connect(this, SIGNAL(clicked()), this, SLOT(startVerifyThread())); # connect(verifyThread, SIGNAL(verifySignal(bool)), this, SLOT(doAfterVerification(bool))); # } # void QtBoxFuncPushButton2::startVerifyThread() # { # verifyThread->start(); # } # void QtBoxFuncPushButton2::doAfterVerification(bool verifyResult) # { # if (!verifyResult) { # verifyNotOk(); # } # else { # verifyOk(); # } # } # void QtBoxFuncPushButton2::verifyNotOk() # { # QMessageBox::critical(this, "Verify", "Wrong username or password"); # } # void QtBoxFuncPushButton2::verifyOk() # { # QMessageBox::information(this, "Verify", "Login successfully"); # # } # #include "verifythread.h" # VerifyThread::VerifyThread() # { # } # void VerifyThread::run() # { # emit verifySignal(verify()); # } # bool VerifyThread::verify() # { # // verify username and password here # return false; # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/func/demo3.py ================================================ # PyQt import webbrowser from PyQt5.QtWidgets import QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxFuncButton3(QPushButton): def __init__(self): super(QtBoxFuncButton3, self).__init__(str(Path(__file__))) self.setText("Open a website") self.clicked.connect(self.open_a_website) def open_a_website(self): url = "https://github.com/la-vie-est-belle/qtbox" webbrowser.open(url) # PyQt # PySide # import webbrowser # from PySide2.QtWidgets import QPushButton # class QtBoxFuncButton3(QPushButton): # def __init__(self): # super(QtBoxFuncButton3, self).__init__() # self.setText("Open a website") # self.clicked.connect(self.open_a_website) # def open_a_website(self): # url = "https://github.com/la-vie-est-belle/qtbox" # webbrowser.open(url) # PySide # C++/Qt # #ifndef QTBOXFUNCPUSHBUTTON3_H # #define QTBOXFUNCPUSHBUTTON3_H # #include # class QtBoxFuncPushButton3 : public QPushButton # { # Q_OBJECT # public: # QtBoxFuncPushButton3(QWidget *parent = nullptr); # private slots: # void openAWebsite(); # }; # #endif // QTBOXFUNCPUSHBUTTON3_H # #include "qtboxfuncpushbutton3.h" # #include # #include # QtBoxFuncPushButton3::QtBoxFuncPushButton3(QWidget *parent) # : QPushButton(parent) # { # setText("Open a website"); # connect(this, SIGNAL(clicked()), this, SLOT(openAWebsite())); # } # void QtBoxFuncPushButton3::openAWebsite() # { # QUrl url = QUrl("https://github.com/la-vie-est-belle/qtbox"); # QDesktopServices::openUrl(url); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/pushbutton/style/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxStyleButton1(QPushButton): def __init__(self): super(QtBoxStyleButton1, self).__init__(str(Path(__file__))) self.setFixedSize(150, 50) self.setText("BUTTON") self.setStyleSheet(""" QPushButton { background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.3, stop:0 #8a9195, stop:1 black); color: white; font-size: 20px; font-weight: bold; border-radius: 25px; } QPushButton:hover { background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.3, stop:0 #7d8488, stop:1 black); } QPushButton:pressed { background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.3, stop:0 #6a7073, stop:1 black); } """) # PyQt # PySide # from PySide2.QtWidgets import QPushButton # class QtBoxStyleButton1(QPushButton): # def __init__(self): # super(QtBoxStyleButton1, self).__init__() # self.setFixedSize(150, 50) # self.setText("BUTTON") # self.setStyleSheet(""" # QPushButton { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.3, stop:0 #8a9195, stop:1 black); # color: white; # font-size: 20px; # font-weight: bold; # border-radius: 25px; # } # QPushButton:hover { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.3, stop:0 #7d8488, stop:1 black); # } # QPushButton:pressed { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.3, stop:0 #6a7073, stop:1 black); # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON1_H # #define QTBOXSTYLEPUSHBUTTON1_H # #include # class QtBoxStylePushButton1 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPUSHBUTTON1_H # #include "qtboxstylepushbutton1.h" # QtBoxStylePushButton1::QtBoxStylePushButton1(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(150, 50); # setText("BUTTON"); # setStyleSheet(R"( # QPushButton { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.3, stop:0 #8a9195, stop:1 black); # color: white; # font-size: 20px; # font-weight: bold; # border-radius: 25px; # } # QPushButton:hover { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.3, stop:0 #7d8488, stop:1 black); # } # QPushButton:pressed { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:0.3, stop:0 #6a7073, stop:1 black); # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo10.py ================================================ # PyQt from PyQt5.QtCore import Qt, QRectF from PyQt5.QtWidgets import QPushButton from PyQt5.QtGui import QPainter, QPen, QColor, QLinearGradient, QFont, QFontMetricsF from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxStyleButton10(QPushButton): def __init__(self): super(QtBoxStyleButton10, self).__init__(str(Path(__file__))) self.btn_rect = None self.btn_state = "off" self.setFixedSize(90, 90) def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) if self.btn_state == "on": offset = 40 font_size = 15 else: offset = 30 font_size = 20 painter.setPen(Qt.NoPen) base_linear_gradient = QLinearGradient(self.rect().topLeft(), self.rect().bottomRight()) base_linear_gradient.setColorAt(0, QColor(117, 117, 117)) base_linear_gradient.setColorAt(1, QColor(97, 97, 97)) painter.setBrush(base_linear_gradient) painter.drawEllipse(self.rect()) self.btn_rect = QRectF(self.rect().left()+offset/2, self.rect().top()+offset/2, self.rect().width()-offset, self.rect().height()-offset) btn_linear_gradient = QLinearGradient(self.btn_rect.topLeft(), self.btn_rect.bottomRight()) btn_linear_gradient.setColorAt(0, QColor(241, 112, 117)) btn_linear_gradient.setColorAt(1, QColor(223, 84, 89)) painter.setBrush(btn_linear_gradient) painter.drawEllipse(self.btn_rect) pen = QPen() pen.setColor(Qt.white) painter.setPen(pen) font = QFont() font.setBold(True) font.setPixelSize(font_size) painter.setFont(font) font_metrics = QFontMetricsF(font) text_width = font_metrics.width("BTN") painter.drawText(int(self.rect().width()/2-text_width/2), int(self.rect().height()/2+5), "BTN") def mousePressEvent(self, event): if event.button() != Qt.LeftButton or not self.btn_rect.contains(event.pos()): return self.btn_state = "on" self.update() def mouseReleaseEvent(self, event): self.btn_state = "off" self.update() # PyQt # PySide # from PySide2.QtCore import Qt, QRectF # from PySide2.QtWidgets import QPushButton # from PySide2.QtGui import QPainter, QPen, QColor, QLinearGradient, QFont, QFontMetricsF # class QtBoxStyleButton10(QPushButton): # def __init__(self): # super(QtBoxStyleButton10, self).__init__() # self.btn_rect = None # self.btn_state = "off" # self.setFixedSize(90, 90) # def paintEvent(self, event): # painter = QPainter(self) # painter.setRenderHint(QPainter.Antialiasing) # if self.btn_state == "on": # offset = 40 # font_size = 15 # else: # offset = 30 # font_size = 20 # painter.setPen(Qt.NoPen) # base_linear_gradient = QLinearGradient(self.rect().topLeft(), self.rect().bottomRight()) # base_linear_gradient.setColorAt(0, QColor(117, 117, 117)) # base_linear_gradient.setColorAt(1, QColor(97, 97, 97)) # painter.setBrush(base_linear_gradient) # painter.drawEllipse(self.rect()) # self.btn_rect = QRectF(self.rect().left()+offset/2, self.rect().top()+offset/2, self.rect().width()-offset, self.rect().height()-offset) # btn_linear_gradient = QLinearGradient(self.btn_rect.topLeft(), self.btn_rect.bottomRight()) # btn_linear_gradient.setColorAt(0, QColor(241, 112, 117)) # btn_linear_gradient.setColorAt(1, QColor(223, 84, 89)) # painter.setBrush(btn_linear_gradient) # painter.drawEllipse(self.btn_rect) # pen = QPen() # pen.setColor(Qt.white) # painter.setPen(pen) # font = QFont() # font.setBold(True) # font.setPixelSize(font_size) # painter.setFont(font) # font_metrics = QFontMetricsF(font) # text_width = font_metrics.width("BTN") # painter.drawText(int(self.rect().width()/2-text_width/2), int(self.rect().height()/2+5), "BTN") # def mousePressEvent(self, event): # if event.button() != Qt.LeftButton or not self.btn_rect.contains(event.pos()): # return # self.btn_state = "on" # self.update() # def mouseReleaseEvent(self, event): # self.btn_state = "off" # self.update() # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON10_H # #define QTBOXSTYLEPUSHBUTTON10_H # #include # #include # #include # #include # #include # class QtBoxStylePushButton10 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton10(QWidget *parent = nullptr); # protected: # void paintEvent(QPaintEvent *event); # void mousePressEvent(QMouseEvent *event); # void mouseReleaseEvent(QMouseEvent *event); # private: # QRectF btnRect; # QString btnState; # }; # #endif // QTBOXSTYLEPUSHBUTTON10_H # #include "qtboxstylepushbutton10.h" # #include # #include # #include # #include # #include # QtBoxStylePushButton10::QtBoxStylePushButton10(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(90, 90); # } # void QtBoxStylePushButton10::paintEvent(QPaintEvent *event) # { # QPainter painter = QPainter(this); # painter.setRenderHint(QPainter::Antialiasing); # int offset; # int fontSize; # if (btnState == "on") { # offset = 40; # fontSize = 15; # } # else { # offset = 30; # fontSize = 20; # } # painter.setPen(Qt::NoPen); # QLinearGradient baseLinearGradient; # baseLinearGradient = QLinearGradient(rect().topLeft(), rect().bottomRight()); # baseLinearGradient.setColorAt(0, QColor(117, 117, 117)); # baseLinearGradient.setColorAt(1, QColor(97, 97, 97)); # painter.setBrush(baseLinearGradient); # painter.drawEllipse(rect()); # btnRect = QRectF(rect().left()+offset/2, rect().top()+offset/2, rect().width()-offset, rect().height()-offset); # baseLinearGradient = QLinearGradient(rect().topLeft(), rect().bottomRight()); # baseLinearGradient.setColorAt(0, QColor(241, 112, 117)); # baseLinearGradient.setColorAt(1, QColor(223, 84, 89)); # painter.setBrush(baseLinearGradient); # painter.drawEllipse(btnRect); # QPen pen = QPen(); # pen.setColor(Qt::white); # painter.setPen(pen); # QFont font = QFont(); # font.setBold(true); # font.setPixelSize(fontSize); # painter.setFont(font); # QFontMetricsF fontMetrics = QFontMetricsF(font); # float textWidth = fontMetrics.size(Qt::TextSingleLine, "BTN").width(); # painter.drawText(int(rect().width()/2-textWidth/2), int(rect().height()/2+5), "BTN"); # } # void QtBoxStylePushButton10::mousePressEvent(QMouseEvent *event) # { # if (event->button() != Qt::LeftButton || !btnRect.contains(event->pos())) { # return; # } # btnState = "on"; # update(); # } # void QtBoxStylePushButton10::mouseReleaseEvent(QMouseEvent *event) # { # btnState = "off"; # update(); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo11.py ================================================ # PyQt from PyQt5.QtCore import Qt, QRectF from PyQt5.QtWidgets import QPushButton from PyQt5.QtGui import QPainter, QPen, QColor, QFont from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxStyleButton11(QPushButton): def __init__(self): super(QtBoxStyleButton11, self).__init__(str(Path(__file__))) self.btn_state = "off" self.setFixedSize(90, 90) self.setWindowFlags(Qt.WindowCloseButtonHint | Qt.MSWindowsFixedSizeDialogHint) def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) if self.btn_state == "on": font_size = 15 shadow_color = QColor(176, 176, 176) white_part_color = QColor(238, 238, 238) else: font_size = 16 shadow_color = QColor(208, 208, 208) white_part_color = QColor(252, 252, 252) painter.setPen(Qt.NoPen) painter.setBrush(shadow_color) btn_shadow_part_rect = self.rect() painter.drawRoundedRect(btn_shadow_part_rect, 5, 5) offset = 20 btn_white_part_rect = QRectF(self.rect().left()+offset/2, self.rect().top()+offset/4, self.rect().width()-offset, self.rect().height()-offset) painter.setBrush(white_part_color) painter.drawRoundedRect(btn_white_part_rect, 5, 5) pen = QPen() pen.setColor(Qt.black) painter.setPen(pen) font = QFont() font.setBold(True) font.setPixelSize(font_size) painter.setFont(font) painter.drawText(int(btn_white_part_rect.x()+2), int(btn_white_part_rect.y()+font_size), "BTN") def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.setFixedSize(86, 86) self.btn_state = "on" self.update() def mouseReleaseEvent(self, event): if event.button() == Qt.LeftButton: self.setFixedSize(90, 90) self.btn_state = "off" self.update() # PyQt # PySide # from PySide2.QtCore import Qt, QRectF # from PySide2.QtWidgets import QPushButton # from PySide2.QtGui import QPainter, QPen, QColor, QFont # class QtBoxStyleButton11(QPushButton): # def __init__(self): # super(QtBoxStyleButton11, self).__init__() # self.btn_state = "off" # self.setFixedSize(90, 90) # self.setWindowFlags(Qt.WindowCloseButtonHint | Qt.MSWindowsFixedSizeDialogHint) # def paintEvent(self, event): # painter = QPainter(self) # painter.setRenderHint(QPainter.Antialiasing) # if self.btn_state == "on": # font_size = 15 # shadow_color = QColor(176, 176, 176) # white_part_color = QColor(238, 238, 238) # else: # font_size = 16 # shadow_color = QColor(208, 208, 208) # white_part_color = QColor(252, 252, 252) # painter.setPen(Qt.NoPen) # painter.setBrush(shadow_color) # btn_shadow_part_rect = self.rect() # painter.drawRoundedRect(btn_shadow_part_rect, 5, 5) # offset = 20 # btn_white_part_rect = QRectF(self.rect().left() + offset / 2, self.rect().top() + offset / 4, self.rect().width() - offset, self.rect().height() - offset) # painter.setBrush(white_part_color) # painter.drawRoundedRect(btn_white_part_rect, 5, 5) # pen = QPen() # pen.setColor(Qt.black) # painter.setPen(pen) # font = QFont() # font.setBold(True) # font.setPixelSize(font_size) # painter.setFont(font) # painter.drawText(int(btn_white_part_rect.x() + 2), int(btn_white_part_rect.y() + font_size), "BTN") # def mousePressEvent(self, event): # if event.button() == Qt.LeftButton: # self.setFixedSize(86, 86) # self.btn_state = "on" # self.update() # def mouseReleaseEvent(self, event): # if event.button() == Qt.LeftButton: # self.setFixedSize(90, 90) # self.btn_state = "off" # self.update() # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON11_H # #define QTBOXSTYLEPUSHBUTTON11_H # #include # #include # #include # #include # class QtBoxStylePushButton11 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton11(QWidget *parent = nullptr); # protected: # void paintEvent(QPaintEvent *event); # void mousePressEvent(QMouseEvent *event); # void mouseReleaseEvent(QMouseEvent *event); # private: # QString btnState = "off"; # }; # #endif // QTBOXSTYLEPUSHBUTTON11_H # #include "qtboxstylepushbutton11.h" # #include # #include # #include # #include # #include # #include # #include # QtBoxStylePushButton11::QtBoxStylePushButton11(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(90, 90); # setWindowFlags(Qt::WindowCloseButtonHint | Qt::MSWindowsFixedSizeDialogHint); # } # void QtBoxStylePushButton11::paintEvent(QPaintEvent *event) # { # QPainter painter = QPainter(this); # painter.setRenderHint(QPainter::Antialiasing); # int fontSize; # QColor shadowColor; # QColor whitePartColor; # if (btnState == "on") { # fontSize = 15; # shadowColor = QColor(176, 176, 176); # whitePartColor = QColor(238, 238, 238); # } # else { # fontSize = 16; # shadowColor = QColor(208, 208, 208); # whitePartColor = QColor(252, 252, 252); # } # painter.setPen(Qt::NoPen); # painter.setBrush(shadowColor); # QRectF btnShadowPartRect = rect(); # painter.drawRoundedRect(btnShadowPartRect, 5, 5); # int offset = 20; # QRectF btnWhitePartRect = QRectF(rect().left()+offset/2, rect().top()+offset/4, rect().width()-offset, rect().height()-offset); # painter.setBrush(whitePartColor); # painter.drawRoundedRect(btnWhitePartRect, 5, 5); # QPen pen = QPen(); # pen.setColor(Qt::black); # painter.setPen(pen); # QFont font = QFont(); # font.setBold(true); # font.setPixelSize(fontSize); # painter.setFont(font); # painter.drawText(int(btnWhitePartRect.x()+2), int(btnWhitePartRect.y()+fontSize), "BTN"); # } # void QtBoxStylePushButton11::mousePressEvent(QMouseEvent *event) # { # if (event->button() == Qt::LeftButton) { # setFixedSize(86, 86); # btnState = "on"; # update(); # } # } # void QtBoxStylePushButton11::mouseReleaseEvent(QMouseEvent *event) # { # if (event->button() == Qt::LeftButton) { # setFixedSize(90, 90); # btnState = "off"; # update(); # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo12.py ================================================ # PyQt from PyQt5.QtCore import pyqtProperty, QPropertyAnimation from PyQt5.QtWidgets import QPushButton from PyQt5.QtGui import QColor from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxStyleButton12(QPushButton): def __init__(self): super(QtBoxStyleButton12, self).__init__(str(Path(__file__))) self.setFixedSize(150, 40) self.setText("BUTTON") self._color = QColor() self.color_anim = QPropertyAnimation(self, b"color") self.color_anim.setDuration(6000) self.color_anim.setStartValue(QColor(0, 0, 0)) self.color_anim.setEndValue(QColor(255, 255, 255)) self.color_anim.start() @pyqtProperty(QColor) def color(self): return self._color @color.setter def color(self, value): self._color = value red = value.red() green = value.green() blue = value.blue() self.setStyleSheet(f"background-color: rgb({red}, {green}, {blue})") # PyQt # PySide # from PySide2.QtCore import Property, QPropertyAnimation # from PySide2.QtWidgets import QPushButton # from PySide2.QtGui import QColor # class QtBoxStyleButton12(QPushButton): # def __init__(self): # super(QtBoxStyleButton12, self).__init__() # self.setFixedSize(150, 40) # self.setText("BUTTON") # self._color = QColor() # self.color_anim = QPropertyAnimation(self, b"color") # self.color_anim.setDuration(6000) # self.color_anim.setStartValue(QColor(0, 0, 0)) # self.color_anim.setEndValue(QColor(255, 255, 255)) # self.color_anim.start() # @Property(QColor) # def color(self): # return self._color # @color.setter # def color(self, value): # self._color = value # red = value.red() # green = value.green() # blue = value.blue() # self.setStyleSheet(f"background-color: rgb({red}, {green}, {blue})") # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON12_H # #define QTBOXSTYLEPUSHBUTTON12_H # #include # #include # class QtBoxStylePushButton12 : public QPushButton # { # Q_OBJECT # Q_PROPERTY(QColor color READ color WRITE setColor); # public: # QtBoxStylePushButton12(QWidget *parent = nullptr); # QColor color() const; # void setColor(const QColor &value); # private: # QColor _color; # }; # #endif // QTBOXSTYLEPUSHBUTTON12_H # #include "qtboxstylepushbutton12.h" # #include # QtBoxStylePushButton12::QtBoxStylePushButton12(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(150, 40); # setText("BUTTON"); # QPropertyAnimation *colorAnim = new QPropertyAnimation(this, "color"); # colorAnim->setDuration(1000); # colorAnim->setStartValue(QColor(0, 0, 0)); # colorAnim->setEndValue(QColor(255, 255, 255)); # colorAnim->start(); # } # QColor QtBoxStylePushButton12::color() const # { # return _color; # } # void QtBoxStylePushButton12::setColor(const QColor &value) # { # _color = value; # int red = value.red(); # int green = value.green(); # int blue = value.blue(); # setStyleSheet(QString("background-color: rgb(%1, %2, %3)").arg(QString::number(red), QString::number(green), QString::number(blue))); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo2.py ================================================ # PyQt from PyQt5.QtWidgets import QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxStyleButton2(QPushButton): def __init__(self): super(QtBoxStyleButton2, self).__init__(str(Path(__file__))) self.setFixedSize(150, 50) self.setText("BUTTON") self.setStyleSheet(""" QPushButton { background-color: qlineargradient(x1:0, y1:0.5, x2:1, y2:0.5, stop:0 #47a7ed, stop: 1 #a967b2); color: white; font-size: 20px; font-weight: bold; border-radius: 25px; } QPushButton:hover { background-color: qlineargradient(x1:0, y1:0.5, x2:1, y2:0.5, stop:0 #459ee0, stop: 1 #995da1); } QPushButton:pressed { background-color: qlineargradient(x1:0, y1:0.5, x2:1, y2:0.5, stop:0 #4093d1, stop: 1 #87538e); } """) # PyQt # PySide # from PySide2.QtWidgets import QPushButton # class QtBoxStyleButton2(QPushButton): # def __init__(self): # super(QtBoxStyleButton2, self).__init__() # self.setFixedSize(150, 50) # self.setText("BUTTON") # self.setStyleSheet(""" # QPushButton { # background-color: qlineargradient(x1:0, y1:0.5, x2:1, y2:0.5, stop:0 #47a7ed, stop: 1 #a967b2); # color: white; # font-size: 20px; # font-weight: bold; # border-radius: 25px; # } # QPushButton:hover { # background-color: qlineargradient(x1:0, y1:0.5, x2:1, y2:0.5, stop:0 #459ee0, stop: 1 #995da1); # } # QPushButton:pressed { # background-color: qlineargradient(x1:0, y1:0.5, x2:1, y2:0.5, stop:0 #4093d1, stop: 1 #87538e); # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON2_H # #define QTBOXSTYLEPUSHBUTTON2_H # #include # class QtBoxStylePushButton2 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton2(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPUSHBUTTON2_H # #include "qtboxstylepushbutton2.h" # QtBoxStylePushButton2::QtBoxStylePushButton2(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(150, 50); # setText("BUTTON"); # setStyleSheet(R"( # QPushButton { # background-color: qlineargradient(x1:0, y1:0.5, x2:1, y2:0.5, stop:0 #47a7ed, stop: 1 #a967b2); # color: white; # font-size: 20px; # font-weight: bold; # border-radius: 25px; # } # QPushButton:hover { # background-color: qlineargradient(x1:0, y1:0.5, x2:1, y2:0.5, stop:0 #459ee0, stop: 1 #995da1); # } # QPushButton:pressed { # background-color: qlineargradient(x1:0, y1:0.5, x2:1, y2:0.5, stop:0 #4093d1, stop: 1 #87538e); # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo3.py ================================================ # PyQt from PyQt5.QtWidgets import QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxStyleButton3(QPushButton): def __init__(self): super(QtBoxStyleButton3, self).__init__(str(Path(__file__))) self.setFixedSize(90, 90) self.setText("BTN") self.setStyleSheet(""" QPushButton { background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #454b4f, stop: 1 #1d2225); color: white; border-radius: 45px; font-size: 18px; font-weight: bold; border: 10px solid #f9f9f9; } QPushButton:hover { border: 10px solid white; background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #35393c, stop: 1 #101214); } QPushButton:pressed { color: black; border: 10px solid black; background-color: white; } """) # PyQt # PySide # from PySide2.QtWidgets import QPushButton # class QtBoxStyleButton3(QPushButton): # def __init__(self): # super(QtBoxStyleButton3, self).__init__() # self.setFixedSize(90, 90) # self.setText("BTN") # self.setStyleSheet(""" # QPushButton { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #454b4f, stop: 1 #1d2225); # color: white; # border-radius: 45px; # font-size: 18px; # font-weight: bold; # border: 10px solid #f9f9f9; # } # QPushButton:hover { # border: 10px solid white; # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #35393c, stop: 1 #101214); # } # QPushButton:pressed { # color: black; # border: 10px solid black; # background-color: white; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON3_H # #define QTBOXSTYLEPUSHBUTTON3_H # #include # class QtBoxStylePushButton3 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton3(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPUSHBUTTON3_H # #include "qtboxstylepushbutton3.h" # QtBoxStylePushButton3::QtBoxStylePushButton3(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(90, 90); # setText("BTN"); # setStyleSheet(R"( # QPushButton { # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #454b4f, stop: 1 #1d2225); # color: white; # border-radius: 45px; # font-size: 18px; # font-weight: bold; # border: 10px solid #f9f9f9; # } # QPushButton:hover { # border: 10px solid white; # background-color: qlineargradient(x1:1, y1:0, x2:1, y2:1, stop:0 #35393c, stop: 1 #101214); # } # QPushButton:pressed { # color: black; # border: 10px solid black; # background-color: white; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo4.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QPushButton from PyQt5.QtGui import QPainter, QPen, QColor, QPainterPath, QFont, QFontMetricsF from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxStyleButton4(QPushButton): def __init__(self): super(QtBoxStyleButton4, self).__init__(str(Path(__file__))) self.btn_state = "normal" self.setFixedSize(90, 90) self.setAttribute(Qt.WA_TranslucentBackground) self.setStyleSheet(""" QPushButton { font-size: 20px; font-weight: bold; } """) def paintEvent(self, event): painter = QPainter(self) if self.btn_state == "normal": painter.setBrush(QColor(59, 63, 66)) pen = QPen() pen.setColor(Qt.white) pen .setWidth(3) painter.setPen(pen) elif self.btn_state == "hover": painter.setBrush(Qt.black) pen = QPen() pen.setColor(Qt.white) pen.setWidth(3) painter.setPen(pen) elif self.btn_state == "press": painter.setBrush(Qt.white) pen = QPen() pen.setColor(Qt.black) pen.setWidth(3) painter.setPen(pen) path = QPainterPath() path.moveTo(self.rect().left()+self.rect().width()/2, self.rect().top()) path.lineTo(self.rect().bottomLeft()) path.lineTo(self.rect().bottomRight()) path.lineTo(self.rect().left()+self.rect().width()/2, self.rect().top()) painter.drawPath(path) font = QFont() font.setBold(True) font.setPixelSize(20) painter.setFont(font) font_metrics = QFontMetricsF(font) text_width = font_metrics.width("BTN") painter.drawText(int(self.rect().width()/2-text_width/2), int(self.rect().height()/2+20), "BTN") def mousePressEvent(self, event): self.btn_state = "press" self.update() def mouseReleaseEvent(self, event): self.btn_state = "hover" self.update() def enterEvent(self, event): self.btn_state = "hover" self.update() def leaveEvent(self, event): self.btn_state = "normal" self.update() # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QPushButton # from PySide2.QtGui import QPainter, QPen, QColor, QPainterPath, QFont, QFontMetricsF # class QtBoxStyleButton4(QPushButton): # def __init__(self): # super(QtBoxStyleButton4, self).__init__() # self.btn_state = "normal" # self.setFixedSize(90, 90) # self.setAttribute(Qt.WA_TranslucentBackground) # self.setStyleSheet(""" # QPushButton { # font-size: 20px; # font-weight: bold; # } # """) # def paintEvent(self, event): # painter = QPainter(self) # if self.btn_state == "normal": # painter.setBrush(QColor(59, 63, 66)) # pen = QPen() # pen.setColor(Qt.white) # pen .setWidth(3) # painter.setPen(pen) # elif self.btn_state == "hover": # painter.setBrush(Qt.black) # pen = QPen() # pen.setColor(Qt.white) # pen.setWidth(3) # painter.setPen(pen) # elif self.btn_state == "press": # painter.setBrush(Qt.white) # pen = QPen() # pen.setColor(Qt.black) # pen.setWidth(3) # painter.setPen(pen) # path = QPainterPath() # path.moveTo(self.rect().left()+self.rect().width()/2, self.rect().top()) # path.lineTo(self.rect().bottomLeft()) # path.lineTo(self.rect().bottomRight()) # path.lineTo(self.rect().left()+self.rect().width()/2, self.rect().top()) # painter.drawPath(path) # font = QFont() # font.setBold(True) # font.setPixelSize(20) # painter.setFont(font) # font_metrics = QFontMetricsF(font) # text_width = font_metrics.width("BTN") # painter.drawText(int(self.rect().width()/2-text_width/2), int(self.rect().height()/2+20), "BTN") # def mousePressEvent(self, event): # self.btn_state = "press" # self.update() # def mouseReleaseEvent(self, event): # self.btn_state = "hover" # self.update() # def enterEvent(self, event): # self.btn_state = "hover" # self.update() # def leaveEvent(self, event): # self.btn_state = "normal" # self.update() # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON4_H # #define QTBOXSTYLEPUSHBUTTON4_H # #include # #include # #include # #include # #include # #include # class QtBoxStylePushButton4 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton4(QWidget *parent = nullptr); # protected: # void paintEvent(QPaintEvent *evnet); # void mousePressEvent(QMouseEvent *event); # void mouseReleaseEvent(QMouseEvent *event); # void enterEvent(QEnterEvent *event); # void leaveEvent(QEvent *event); # private: # QString btnState = "normal"; # }; # #endif // QTBOXSTYLEPUSHBUTTON4_H # #include "qtboxstylepushbutton4.h" # #include # #include # #include # #include # #include # #include # #include # QtBoxStylePushButton4::QtBoxStylePushButton4(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(90, 90); # setAttribute(Qt::WA_TranslucentBackground); # setStyleSheet(R"( # QPushButton { # font-size: 20px; # font-weight: bold; # } # )"); # } # void QtBoxStylePushButton4::paintEvent(QPaintEvent *event) # { # QPainter painter = QPainter(this); # if (btnState == "normal") { # painter.setBrush(QColor(59, 63, 66)); # QPen pen = QPen(); # pen.setColor(Qt::white); # pen.setWidth(3); # painter.setPen(pen); # } # else if (btnState == "hover") { # painter.setBrush(Qt::black); # QPen pen = QPen(); # pen.setColor(Qt::white); # pen.setWidth(3); # painter.setPen(pen); # } # else if (btnState == "press") { # painter.setBrush(Qt::white); # QPen pen = QPen(); # pen.setColor(Qt::black); # pen.setWidth(3); # painter.setPen(pen); # } # QPainterPath path = QPainterPath(); # path.moveTo(rect().left()+rect().width()/2, rect().top()); # path.lineTo(rect().bottomLeft()); # path.lineTo(rect().bottomRight()); # path.lineTo(rect().left()+rect().width()/2, rect().top()); # painter.drawPath(path); # QFont font = QFont(); # font.setBold(true); # font.setPixelSize(20); # painter.setFont(font); # QFontMetricsF fontMetrics = QFontMetricsF(font); # float textWidth = fontMetrics.size(Qt::TextSingleLine, "BTN").width(); # painter.drawText(int(rect().width()/2-textWidth/2), int(rect().height()/2+20), "BTN"); # } # void QtBoxStylePushButton4::mousePressEvent(QMouseEvent *event) # { # btnState = "press"; # update(); # } # void QtBoxStylePushButton4::mouseReleaseEvent(QMouseEvent *event) # { # btnState = "hover"; # update(); # } # void QtBoxStylePushButton4::enterEvent(QEnterEvent *event) # { # btnState = "hover"; # update(); # } # void QtBoxStylePushButton4::leaveEvent(QEvent *event) # { # btnState = "normal"; # update(); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo5.py ================================================ # PyQt from PyQt5.QtGui import QIcon from PyQt5.QtCore import QSize from PyQt5.QtWidgets import QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) PATH_TO_IMG = str(Path(__file__).parent.parent.parent.parent / "res/images/plus.png").replace("\\", "/") class QtBoxStyleButton5(QPushButton): def __init__(self): super(QtBoxStyleButton5, self).__init__(str(Path(__file__))) self.setFixedSize(90, 90) self.setIconSize(QSize(80, 80)) self.setIcon(QIcon(PATH_TO_IMG)) self.setStyleSheet(""" QPushButton { background-color: qlineargradient(x1:1, y1:0, x2:0, y2:1, stop:0 #f9ab6a, stop: 1 #f08833); border-radius: 45px; border: none } QPushButton:hover { background-color: qlineargradient(x1:1, y1:0, x2:0, y2:1, stop:0 #f7a25b, stop: 1 #f19040); } QPushButton:pressed { background-color: qlineargradient(x1:1, y1:0, x2:0, y2:1, stop:0 #e39b5f, stop: 1 #e58637); } """) # PyQt # PySide # from PySide2.QtGui import QIcon # from PySide2.QtCore import QSize # from PySide2.QtWidgets import QPushButton # class QtBoxStyleButton5(QPushButton): # def __init__(self): # super(QtBoxStyleButton5, self).__init__() # self.setFixedSize(90, 90) # self.setIconSize(QSize(80, 80)) # self.setIcon(QIcon(PATH_TO_IMG)) # self.setStyleSheet(""" # QPushButton { # background-color: qlineargradient(x1:1, y1:0, x2:0, y2:1, stop:0 #f9ab6a, stop: 1 #f08833); # border-radius: 45px; # border: none # } # QPushButton:hover { # background-color: qlineargradient(x1:1, y1:0, x2:0, y2:1, stop:0 #f7a25b, stop: 1 #f19040); # } # QPushButton:pressed { # background-color: qlineargradient(x1:1, y1:0, x2:0, y2:1, stop:0 #e39b5f, stop: 1 #e58637); # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON5_H # #define QTBOXSTYLEPUSHBUTTON5_H # #include # class QtBoxStylePushButton5 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton5(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPUSHBUTTON5_H # #include "qtboxstylepushbutton5.h" # #include # #include # QtBoxStylePushButton5::QtBoxStylePushButton5(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(90, 90); # setIconSize(QSize(80, 80)); # setIcon(QIcon(PATH_TO_IMG)); # setStyleSheet(R"( # QPushButton { # background-color: qlineargradient(x1:1, y1:0, x2:0, y2:1, stop:0 #f9ab6a, stop: 1 #f08833); # border-radius: 45px; # border: none # } # QPushButton:hover { # background-color: qlineargradient(x1:1, y1:0, x2:0, y2:1, stop:0 #f7a25b, stop: 1 #f19040); # } # QPushButton:pressed { # background-color: qlineargradient(x1:1, y1:0, x2:0, y2:1, stop:0 #e39b5f, stop: 1 #e58637); # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo6.py ================================================ # PyQt from PyQt5.QtWidgets import QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxStyleButton6(QPushButton): def __init__(self): super(QtBoxStyleButton6, self).__init__(str(Path(__file__))) self.setFixedSize(150, 40) self.setText("BUTTON") self.setStyleSheet(""" QPushButton { background-color: #57bd6a; color: #f9ffff; font-size: 20px; font-weight: bold; border-radius: 5px; } QPushButton:pressed { background-color: #4eaa5f; } """) # PyQt # PySide # from PySide2.QtWidgets import QPushButton # class QtBoxStyleButton6(QPushButton): # def __init__(self): # super(QtBoxStyleButton6, self).__init__() # self.setFixedSize(150, 40) # self.setText("BUTTON") # self.setStyleSheet(""" # QPushButton { # background-color: #57bd6a; # color: #f9ffff; # font-size: 20px; # font-weight: bold; # border-radius: 5px; # } # QPushButton:pressed { # background-color: #4eaa5f; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON6_H # #define QTBOXSTYLEPUSHBUTTON6_H # #include # class QtBoxStylePushButton6 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton6(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPUSHBUTTON6_H # #include "qtboxstylepushbutton6.h" # QtBoxStylePushButton6::QtBoxStylePushButton6(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(150, 40); # setText("BUTTON"); # setStyleSheet(R"( # QPushButton { # background-color: #57bd6a; # color: #f9ffff; # font-size: 20px; # font-weight: bold; # border-radius: 5px; # } # QPushButton:pressed { # background-color: #4eaa5f; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo7.py ================================================ # PyQt from PyQt5.QtGui import QIcon from PyQt5.QtCore import QSize, Qt from PyQt5.QtWidgets import QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) PATH_TO_IMG = str(Path(__file__).parent.parent.parent.parent / "res/images/search.png").replace("\\", "/") class QtBoxStyleButton7(QPushButton): def __init__(self): super(QtBoxStyleButton7, self).__init__(str(Path(__file__))) self.setText("BUTTON ") self.setFixedSize(150, 40) self.setIconSize(QSize(25, 25)) self.setIcon(QIcon(PATH_TO_IMG)) self.setLayoutDirection(Qt.RightToLeft) self.setStyleSheet(""" QPushButton { background-color: #292929; border-radius: 5px; font-size: 20px; font-weight: bold; color: white; border: 1px solid white; } QPushButton:pressed { background-color: black; } """) # PyQt # PySide # from PySide2.QtGui import QIcon # from PySide2.QtCore import QSize, Qt # from PySide2.QtWidgets import QPushButton # class QtBoxStyleButton7(QPushButton): # def __init__(self): # super(QtBoxStyleButton7, self).__init__() # self.setText("BUTTON ") # self.setFixedSize(150, 40) # self.setIconSize(QSize(25, 25)) # self.setIcon(QIcon(PATH_TO_IMG)) # self.setLayoutDirection(Qt.RightToLeft) # self.setStyleSheet(""" # QPushButton { # background-color: #292929; # border-radius: 5px; # font-size: 20px; # font-weight: bold; # color: white; # border: 1px solid white; # } # QPushButton:pressed { # background-color: black; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON7_H # #define QTBOXSTYLEPUSHBUTTON7_H # #include # class QtBoxStylePushButton7 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton7(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLEPUSHBUTTON7_H # #include "qtboxstylepushbutton7.h" # #include # #include # QtBoxStylePushButton7::QtBoxStylePushButton7(QWidget *parent) # : QPushButton(parent) # { # setText("BUTTON "); # setFixedSize(150, 40); # setIconSize(QSize(25, 25)); # setIcon(QIcon(":res/images/search.png")); # setLayoutDirection(Qt::RightToLeft); # setStyleSheet(R"( # QPushButton { # background-color: #292929; # border-radius: 5px; # font-size: 20px; # font-weight: bold; # color: white; # border: 1px solid white; # } # QPushButton:pressed { # background-color: black; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo8.py ================================================ # PyQt from PyQt5.QtCore import Qt, QRectF from PyQt5.QtWidgets import QPushButton from PyQt5.QtGui import QPainter, QPen, QColor from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxStyleButton8(QPushButton): def __init__(self): super(QtBoxStyleButton8, self).__init__(str(Path(__file__))) self.btn_state = "on" self.setFixedSize(80, 40) def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) pen = QPen(Qt.NoPen) painter.setPen(pen) if self.btn_state == "on": painter.setBrush(QColor(96, 202, 91)) rect = QRectF(0, 0, self.width(), self.height()) painter.drawRoundedRect(rect, self.height()/2, self.height()/2) painter.setBrush(Qt.white) rect = QRectF(self.width()/2-5, 5, self.width()/2, self.height()-5*2) painter.drawRoundedRect(rect, (self.height()-5*2)/2, (self.height()-5*2)/2) else: painter.setBrush(QColor(220, 220, 220)) rect = QRectF(0, 0, self.width(), self.height()) painter.drawRoundedRect(rect, self.height()/2, self.height()/2) painter.setBrush(Qt.white) rect = QRectF(5, 5, self.width()/2, self.height()-5*2) painter.drawRoundedRect(rect, (self.height()-5*2)/2, (self.height()-5*2)/2) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: if self.btn_state == "on": self.btn_state = "off" else: self.btn_state = "on" # PyQt # PySide # from PySide2.QtCore import Qt, QRectF # from PySide2.QtWidgets import QPushButton # from PySide2.QtGui import QPainter, QPen, QColor # class QtBoxStyleButton8(QPushButton): # def __init__(self): # super(QtBoxStyleButton8, self).__init__() # self.btn_state = "on" # self.setFixedSize(80, 40) # def paintEvent(self, event): # painter = QPainter(self) # painter.setRenderHint(QPainter.Antialiasing) # pen = QPen(Qt.NoPen) # painter.setPen(pen) # if self.btn_state == "on": # painter.setBrush(QColor(96, 202, 91)) # rect = QRectF(0, 0, self.width(), self.height()) # painter.drawRoundedRect(rect, self.height()/2, self.height()/2) # painter.setBrush(Qt.white) # rect = QRectF(self.width()/2-5, 5, self.width()/2, self.height()-5*2) # painter.drawRoundedRect(rect, (self.height()-5*2)/2, (self.height()-5*2)/2) # else: # painter.setBrush(QColor(220, 220, 220)) # rect = QRectF(0, 0, self.width(), self.height()) # painter.drawRoundedRect(rect, self.height()/2, self.height()/2) # painter.setBrush(Qt.white) # rect = QRectF(5, 5, self.width()/2, self.height()-5*2) # painter.drawRoundedRect(rect, (self.height()-5*2)/2, (self.height()-5*2)/2) # def mousePressEvent(self, event): # if event.button() == Qt.LeftButton: # if self.btn_state == "on": # self.btn_state = "off" # else: # self.btn_state = "on" # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON8_H # #define QTBOXSTYLEPUSHBUTTON8_H # #include # #include # #include # class QtBoxStylePushButton8 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton8(QWidget *parent = nullptr); # protected: # void paintEvent(QPaintEvent *event); # void mousePressEvent(QMouseEvent *event); # # private: # QString btnState = "on"; # }; # #endif // QTBOXSTYLEPUSHBUTTON8_H # #include "qtboxstylepushbutton8.h" # #include # #include # #include # QtBoxStylePushButton8::QtBoxStylePushButton8(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(80, 40); # } # void QtBoxStylePushButton8::paintEvent(QPaintEvent *event) # { # QPainter painter = QPainter(this); # painter.setRenderHint(QPainter::Antialiasing); # QPen pen = QPen(Qt::NoPen); # painter.setPen(pen); # if (btnState == "on") { # painter.setBrush(QColor(96, 202, 91)); # QRectF rect = QRectF(0, 0, width(), height()); # painter.drawRoundedRect(rect, height()/2, height()/2); # painter.setBrush(Qt::white); # rect = QRectF(width()/2-5, 5, width()/2, height()-5*2); # painter.drawRoundedRect(rect, (height()-5*2)/2, (height()-5*2)/2); # } # else { # painter.setBrush(QColor(220, 220, 220)); # QRectF rect = QRectF(0, 0, width(), height()); # painter.drawRoundedRect(rect, height()/2, height()/2); # painter.setBrush(Qt::white); # rect = QRectF(5, 5, width()/2, height()-5*2); # painter.drawRoundedRect(rect, (height()-5*2)/2, (height()-5*2)/2); # } # } # void QtBoxStylePushButton8::mousePressEvent(QMouseEvent *event) # { # if (event->button() == Qt::LeftButton) { # if (btnState == "on") { # btnState = "off"; # } # else { # btnState = "on"; # } # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/pushbutton/style/demo9.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QPushButton, QGraphicsDropShadowEffect from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QPushButton = createWidgetMenuBase(QPushButton) class QtBoxStyleButton9(QPushButton): def __init__(self): super(QtBoxStyleButton9, self).__init__(str(Path(__file__))) self.setFixedSize(150, 40) self.setText("BUTTON") self.add_shadow() def add_shadow(self): shadow = QGraphicsDropShadowEffect(self) shadow.setBlurRadius(15) shadow.setOffset(3, 3) shadow.setColor(Qt.gray) self.setGraphicsEffect(shadow) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QPushButton, QGraphicsDropShadowEffect # class QtBoxStyleButton9(QPushButton): # def __init__(self): # super(QtBoxStyleButton9, self).__init__() # self.setFixedSize(150, 40) # self.setText("BUTTON") # self.add_shadow() # def add_shadow(self): # shadow = QGraphicsDropShadowEffect(self) # shadow.setBlurRadius(15) # shadow.setOffset(3, 3) # shadow.setColor(Qt.gray) # self.setGraphicsEffect(shadow) # PySide # C++/Qt # #ifndef QTBOXSTYLEPUSHBUTTON9_H # #define QTBOXSTYLEPUSHBUTTON9_H # #include # class QtBoxStylePushButton9 : public QPushButton # { # Q_OBJECT # public: # QtBoxStylePushButton9(QWidget *parent = nullptr); # private: # void addShadow(); # }; # #endif // QTBOXSTYLEPUSHBUTTON9_H # #include "qtboxstylepushbutton9.h" # #include # QtBoxStylePushButton9::QtBoxStylePushButton9(QWidget *parent) # : QPushButton(parent) # { # setFixedSize(150, 40); # setText("BUTTON"); # addShadow(); # } # void QtBoxStylePushButton9::addShadow() # { # QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); # shadow->setBlurRadius(15); # shadow->setOffset(3, 3); # shadow->setColor(Qt::gray); # setGraphicsEffect(shadow); # } # C++/Qt ================================================ FILE: src/qtbox/demo/slider/__init__.py ================================================ from .func import demo1 from .style import demo1, demo2, demo3, demo4, demo5 ================================================ FILE: src/qtbox/demo/slider/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/slider/func/demo1.py ================================================ # PyQt from PyQt5.QtCore import Qt, QRectF from PyQt5.QtGui import QPainter, QColor, QFont, QFontMetricsF from PyQt5.QtWidgets import QSlider from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QSlider = createWidgetMenuBase(QSlider) class QtBoxFuncSlider1(QSlider): def __init__(self): super(QtBoxFuncSlider1, self).__init__(str(Path(__file__))) self.setMinimum(0) self.setMaximum(100) self.setOrientation(Qt.Horizontal) self.is_number_shown = False def mousePressEvent(self, event): super(QtBoxFuncSlider1, self).mousePressEvent(event) if event.button() == Qt.LeftButton: self.is_number_shown = True self.update() def mouseReleaseEvent(self, event): super(QtBoxFuncSlider1, self).mouseReleaseEvent(event) if event.button() == Qt.LeftButton: self.is_number_shown = False self.update() def paintEvent(self, event): super(QtBoxFuncSlider1, self).paintEvent(event) if not self.is_number_shown: return painter = QPainter(self) painter.setBrush(QColor(220, 220, 220, 120)) font = QFont() font.setPixelSize(13) painter.setFont(font) font_metrics = QFontMetricsF(font) text_width = font_metrics.width(str(self.value())) text_height = font_metrics.height() x = (self.value() - self.minimum()) / (self.maximum() - self.minimum()) * (self.width() - text_width) rect = QRectF(x, 0, text_width, text_height) painter.setPen(Qt.NoPen) painter.drawRoundedRect(rect, 3, 3) painter.setPen(Qt.SolidLine) painter.drawText(int(x), int(text_height), str(self.value())) # PyQt # PySide # from PySide2.QtCore import Qt, QRectF # from PySide2.QtGui import QPainter, QColor, QFont, QFontMetricsF # from PySide2.QtWidgets import QSlider # class QtBoxFuncSlider1(QSlider): # def __init__(self): # super(QtBoxFuncSlider1, self).__init__(str(Path(__file__))) # self.setMinimum(0) # self.setMaximum(100) # self.setOrientation(Qt.Horizontal) # self.is_number_shown = False # def mousePressEvent(self, event): # super(QtBoxFuncSlider1, self).mousePressEvent(event) # if event.button() == Qt.LeftButton: # self.is_number_shown = True # self.update() # def mouseReleaseEvent(self, event): # super(QtBoxFuncSlider1, self).mouseReleaseEvent(event) # if event.button() == Qt.LeftButton: # self.is_number_shown = False # self.update() # def paintEvent(self, event): # super(QtBoxFuncSlider1, self).paintEvent(event) # if not self.is_number_shown: # return # painter = QPainter(self) # painter.setBrush(QColor(200, 200, 200, 120)) # font = QFont() # font.setPixelSize(15) # painter.setFont(font) # font_metrics = QFontMetricsF(font) # text_width = font_metrics.width(str(self.value())) # text_height = font_metrics.height() # x = (self.value() - self.minimum()) / (self.maximum() - self.minimum()) * (self.width() - text_width) # rect = QRectF(x, 0, text_width, text_height) # painter.setPen(Qt.NoPen) # painter.drawRoundedRect(rect, 3, 3) # painter.setPen(Qt.SolidLine) # painter.drawText(int(x), int(text_height), str(self.value())) # PySide # C++/Qt # #ifndef QTBOXFUNCSLIDER1_H # #define QTBOXFUNCSLIDER1_H # #include # #include # #include # class QtBoxFuncSlider1 : public QSlider # { # Q_OBJECT # public: # QtBoxFuncSlider1(QWidget *parent = nullptr); # protected: # void mousePressEvent(QMouseEvent *event); # void mouseReleaseEvent(QMouseEvent *event); # void paintEvent(QPaintEvent *event); # private: # bool isNumberShown = false; # }; # #endif // QTBOXFUNCSLIDER1_H # #include "qtboxfuncslider1.h" # #include # #include # #include # #include # #include # #include # QtBoxFuncSlider1::QtBoxFuncSlider1(QWidget *parent) # : QSlider(parent) # { # setMinimum(0); # setMaximum(100); # setOrientation(Qt::Horizontal); # } # void QtBoxFuncSlider1::mousePressEvent(QMouseEvent *event) # { # QSlider::mousePressEvent(event); # if (event->button() == Qt::LeftButton) { # isNumberShown = true; # update(); # } # } # void QtBoxFuncSlider1::mouseReleaseEvent(QMouseEvent *event) # { # # QSlider::mouseReleaseEvent(event); # if (event->button() == Qt::LeftButton) { # isNumberShown = false; # update(); # } # } # void QtBoxFuncSlider1::paintEvent(QPaintEvent *event) # { # QSlider::paintEvent(event); # if (!isNumberShown) { # return; # } # QPainter painter = QPainter(this); # painter.setBrush(QColor(220, 220, 220, 120)); # QFont font = QFont(); # font.setPixelSize(13); # painter.setFont(font); # QFontMetricsF fontMetrics = QFontMetricsF(font); # float textWidth = fontMetrics.size(Qt::TextSingleLine, QString("%1").arg(value())).width(); # float textHeight = fontMetrics.height(); # float x = float(value() - minimum()) / float(maximum() - minimum()) * float(width() - textWidth); # QRectF rect = QRectF(x, 0, textWidth, textHeight*1.3); # painter.setPen(Qt::NoPen); # painter.drawRoundedRect(rect, 3, 3); # painter.setPen(Qt::SolidLine); # painter.drawText(int(x), int(textHeight), QString("%1").arg(value())); # } # C++/Qt ================================================ FILE: src/qtbox/demo/slider/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/slider/style/demo1.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QSlider from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QSlider = createWidgetMenuBase(QSlider) class QtBoxStyleSlider1(QSlider): def __init__(self): super(QtBoxStyleSlider1, self).__init__(str(Path(__file__))) self.setOrientation(Qt.Horizontal) self.setStyleSheet(""" QSlider::groove:horizontal { border: none; height: 2px; background-color: lightgray; } QSlider::handle:horizontal { background-color: #2f77cb; width: 8px; margin: -9px 0px -9px 0px; border-radius: 4px; } QSlider::sub-page:horizontal { background-color: #4898ec; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QSlider # class QtBoxStyleSlider1(QSlider): # def __init__(self): # super(QtBoxStyleSlider1, self).__init__() # self.setOrientation(Qt.Horizontal) # self.setStyleSheet(""" # QSlider::groove:horizontal { # border: none; # height: 2px; # background-color: lightgray; # } # QSlider::handle:horizontal { # background-color: #2f77cb; # width: 8px; # margin: -9px 0px -9px 0px; # border-radius: 4px; # } # QSlider::sub-page:horizontal { # background-color: #4898ec; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLESLIDER1_H # #define QTBOXSTYLESLIDER1_H # #include # class QtBoxStyleSlider1 : public QSlider # { # Q_OBJECT # public: # QtBoxStyleSlider1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLESLIDER1_H # #include "qtboxstyleslider1.h" # QtBoxStyleSlider1::QtBoxStyleSlider1(QWidget *parent) # : QSlider(parent) # { # setOrientation(Qt::Horizontal); # setStyleSheet(R"( # QSlider::groove:horizontal { # border: none; # height: 2px; # background-color: lightgray; # } # QSlider::handle:horizontal { # background-color: #2f77cb; # width: 8px; # margin: -9px 0px -9px 0px; # border-radius: 4px; # } # # QSlider::sub-page:horizontal { # background-color: #4898ec; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/slider/style/demo2.py ================================================ # PyQt from PyQt5.QtWidgets import QSlider from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QSlider = createWidgetMenuBase(QSlider) class QtBoxStyleSlider2(QSlider): def __init__(self): super(QtBoxStyleSlider2, self).__init__(str(Path(__file__))) self.setStyleSheet(""" QSlider::groove:vertical { background-color: #eaebed; border: none; width: 6px; border-radius: 3px; } QSlider::handle:vertical { background-color: #d33124; height:6px; margin: 0px -1px 0px -1px; border-radius: 3px; } QSlider::add-page:vertical { background-color: #d33124; } """) # PyQt # PySide # from PySide2.QtWidgets import QSlider # class QtBoxStyleSlider2(QSlider): # def __init__(self): # super(QtBoxStyleSlider2, self).__init__() # self.setStyleSheet(""" # QSlider::groove:vertical { # background-color: #eaebed; # border: none; # width: 6px; # border-radius: 3px; # } # QSlider::handle:vertical { # background-color: #d33124; # height:6px; # margin: 0px -1px 0px -1px; # border-radius: 3px; # } # QSlider::add-page:vertical { # background-color: #d33124; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLESLIDER2_H # #define QTBOXSTYLESLIDER2_H # #include # class QtBoxStyleSlider2 : public QSlider # { # Q_OBJECT # public: # QtBoxStyleSlider2(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLESLIDER2_H # #include "qtboxstyleslider2.h" # QtBoxStyleSlider2::QtBoxStyleSlider2(QWidget *parent) # : QSlider(parent) # { # setStyleSheet(R"( # QSlider::groove:vertical { # background-color: #eaebed; # border: none; # width: 6px; # border-radius: 3px; # } # QSlider::handle:vertical { # background-color: #d33124; # height:6px; # margin: 0px -1px 0px -1px; # border-radius: 3px; # } # QSlider::add-page:vertical { # background-color: #d33124; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/slider/style/demo3.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QSlider from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QSlider = createWidgetMenuBase(QSlider) class QtBoxStyleSlider3(QSlider): def __init__(self): super(QtBoxStyleSlider3, self).__init__(str(Path(__file__))) self.setOrientation(Qt.Horizontal) self.setStyleSheet(""" QSlider::groove:horizontal { border: none; height: 2px; background-color: lightgray; } QSlider::handle:horizontal { background-color: #f1964c; width: 16px; margin: -8px 0px -8px 0px; border-radius: 8px; } QSlider::sub-page:horizontal { background-color: #f1964c; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QSlider # class QtBoxStyleSlider3(QSlider): # def __init__(self): # super(QtBoxStyleSlider3, self).__init__() # self.setOrientation(Qt.Horizontal) # self.setStyleSheet(""" # QSlider::groove:horizontal { # border: none; # height: 2px; # background-color: lightgray; # } # QSlider::handle:horizontal { # background-color: #f1964c; # width: 16px; # margin-top: -8px 0px -8px 0px; # border-radius: 8px; # } # QSlider::sub-page:horizontal { # background-color: #f1964c; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLESLIDER3_H # #define QTBOXSTYLESLIDER3_H # #include # class QtBoxStyleSlider3 : public QSlider # { # Q_OBJECT # public: # QtBoxStyleSlider3(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLESLIDER3_H # #include "qtboxstyleslider3.h" # QtBoxStyleSlider3::QtBoxStyleSlider3(QWidget *parent) # : QSlider(parent) # { # setOrientation(Qt::Horizontal); # setStyleSheet(R"( # QSlider::groove:horizontal { # border: none; # height: 2px; # background-color: lightgray; # } # QSlider::handle:horizontal { # background-color: #f1964c; # width: 16px; # margin: -8px 0px -8px 0px; # border-radius: 8px; # } # QSlider::sub-page:horizontal { # background-color: #f1964c; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/slider/style/demo4.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QSlider from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QSlider = createWidgetMenuBase(QSlider) PATH_TO_IMG = str(Path(__file__).parent.parent.parent.parent / "res/images/basketball.png").replace("\\", "/") class QtBoxStyleSlider4(QSlider): def __init__(self): super(QtBoxStyleSlider4, self).__init__(str(Path(__file__))) self.setOrientation(Qt.Horizontal) self.setStyleSheet(""" QSlider::groove:horizontal { border: none; height: 2px; background-color: lightgray; } QSlider::handle:horizontal { border-image: url(%s); width: 20px; margin: -10px -2px -10px -2px; } QSlider::sub-page:horizontal { background-color: #ef7067; } """ % (PATH_TO_IMG)) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QSlider # class QtBoxStyleSlider4(QSlider): # def __init__(self): # super(QtBoxStyleSlider4, self).__init__() # self.setOrientation(Qt.Horizontal) # self.setStyleSheet(""" # QSlider::groove:horizontal { # border: none; # height: 2px; # background-color: lightgray; # } # QSlider::handle:horizontal { # border-image: url(%s); # width: 20px; # margin: -10px -2px -10px -2px; # } # QSlider::sub-page:horizontal { # background-color: #ef7067; # } # """ % (PATH_TO_IMG)) # PySide # C++/Qt # #ifndef QTBOXSTYLESLIDER4_H # #define QTBOXSTYLESLIDER4_H # #include # class QtBoxStyleSlider4 : public QSlider # { # Q_OBJECT # public: # QtBoxStyleSlider4(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLESLIDER4_H # #include "qtboxstyleslider4.h" # QtBoxStyleSlider4::QtBoxStyleSlider4(QWidget *parent) # : QSlider(parent) # { # setOrientation(Qt::Horizontal); # setStyleSheet(R"( # QSlider::groove:horizontal { # border: none; # height: 2px; # background-color: lightgray; # } # QSlider::handle:horizontal { # border-image: url(PATH_TO_IMG); # width: 20px; # margin: -10px -2px -10px -2px; # } # QSlider::sub-page:horizontal { # background-color: #ef7067; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/slider/style/demo5.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QSlider from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QSlider = createWidgetMenuBase(QSlider) class QtBoxStyleSlider5(QSlider): def __init__(self): super(QtBoxStyleSlider5, self).__init__(str(Path(__file__))) self.setOrientation(Qt.Horizontal) self.setStyleSheet(""" QSlider::groove:horizontal { border: none; height: 10px; background-color: lightgray; border-radius: 5px; } QSlider::handle:horizontal { width: 4px; margin: -1px 0px -1px -5px; border-radius: 1px; background-color: white; } QSlider::sub-page:horizontal { background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #59969b, stop:1 #04e7fa); border-radius: 5px; } """) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QSlider # class QtBoxStyleSlider5(QSlider): # def __init__(self): # super(QtBoxStyleSlider5, self).__init__() # self.setOrientation(Qt.Horizontal) # self.setStyleSheet(""" # QSlider::groove:horizontal { # border: none; # height: 10px; # background-color: lightgray; # border-radius: 5px; # } # QSlider::handle:horizontal { # width: 4px; # margin: -1px 0px -1px -5px; # border-radius: 1px; # background-color: white; # } # QSlider::sub-page:horizontal { # background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #59969b, stop:1 #04e7fa); # border-radius: 5px; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLESLIDER5_H # #define QTBOXSTYLESLIDER5_H # #include # class QtBoxStyleSlider5 : public QSlider # { # Q_OBJECT # public: # QtBoxStyleSlider5(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLESLIDER5_H # #include "qtboxstyleslider5.h" # QtBoxStyleSlider5::QtBoxStyleSlider5(QWidget *parent) # : QSlider(parent) # { # setOrientation(Qt::Horizontal); # setStyleSheet(R"( # QSlider::groove:horizontal { # border: none; # height: 10px; # background-color: lightgray; # border-radius: 5px; # } # QSlider::handle:horizontal { # width: 4px; # margin: -1px 0px -1px -5px; # border-radius: 1px; # background-color: white; # } # QSlider::sub-page:horizontal { # background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #59969b, stop:1 #04e7fa); # border-radius: 5px; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/spinbox/__init__.py ================================================ from .func import demo1 from .style import demo1 ================================================ FILE: src/qtbox/demo/spinbox/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/spinbox/func/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QSpinBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QSpinBox = createWidgetMenuBase(QSpinBox) class QtBoxFuncSpinBox1(QSpinBox): def __init__(self): super(QtBoxFuncSpinBox1, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.setPrefix("Sth: ") self.setSuffix(" PCS") # PyQt # PySide # from PySide2.QtWidgets import QSpinBox # class QtBoxFuncSpinBox1(QSpinBox): # def __init__(self): # super(QtBoxFuncSpinBox1, self).__init__(str(Path(__file__))) # self.setFixedSize(150, 30) # self.setPrefix("Sth: ") # self.setSuffix(" PCS") # PySide # C++/Qt # #ifndef QTBOXFUNCSPINBOX1_H # #define QTBOXFUNCSPINBOX1_H # #include # class QtBoxFuncSpinBox1 : public QSpinBox # { # Q_OBJECT # public: # QtBoxFuncSpinBox1(QWidget *parent = nullptr); # }; # #endif // QTBOXFUNCSPINBOX1_H # #include "qtboxfuncspinbox1.h" # QtBoxFuncSpinBox1::QtBoxFuncSpinBox1(QWidget *parent) # : QSpinBox(parent) # { # setFixedSize(150, 30); # setPrefix("Sth: "); # setSuffix(" PCS"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/spinbox/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/spinbox/style/demo1.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QSpinBox from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QSpinBox = createWidgetMenuBase(QSpinBox) PATH_TO_IMG1 = str(Path(__file__).parent.parent.parent.parent / "res/images/up.png").replace("\\", "/") PATH_TO_IMG2 = str(Path(__file__).parent.parent.parent.parent / "res/images/down.png").replace("\\", "/") class QtBoxStyleSpinBox1(QSpinBox): def __init__(self): super(QtBoxStyleSpinBox1, self).__init__(str(Path(__file__))) self.setFixedSize(150, 30) self.setCursor(Qt.PointingHandCursor) self.setAttribute(Qt.WA_MacShowFocusRect, False) self.setStyleSheet(""" QSpinBox { border: 1px solid lightgray; border-radius: 3px; } QSpinBox::up-button { width: 14px; height: 14px; margin: 0px 3px 0px -3px; border-image: url(%s); } QSpinBox::up-button:pressed { margin-top: 1px; } QSpinBox::down-button { width: 14px; height: 14px; margin: 0px 3px 0px -3px; border-image: url(%s); } QSpinBox::down-button:pressed { margin-bottom: 1px; } """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QSpinBox # class QtBoxStyleSpinBox1(QSpinBox): # def __init__(self): # super(QtBoxStyleSpinBox1, self).__init__() # self.setFixedSize(150, 30) # self.setCursor(Qt.PointingHandCursor) # self.setAttribute(Qt.WA_MacShowFocusRect, False) # self.setStyleSheet(""" # QSpinBox { # border: 1px solid lightgray; # border-radius: 3px; # } # QSpinBox::up-button { # margin: 0px 3px 0px -3px; # border-image: url(%s); # } # QSpinBox::up-button:pressed { # margin-top: 1px; # } # QSpinBox::down-button { # margin: 0px 3px 0px -3px; # border-image: url(%s); # } # QSpinBox::down-button:pressed { # margin-bottom: 1px; # } # """ % (PATH_TO_IMG1, PATH_TO_IMG2)) # PySide # C++/Qt # #ifndef QTBOXSTYLESPINBOX1_H # #define QTBOXSTYLESPINBOX1_H # #include # class QtBoxStyleSpinBox1 : public QSpinBox # { # Q_OBJECT # public: # QtBoxStyleSpinBox1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLESPINBOX1_H # #include "qtboxstylespinbox1.h" # #include # QtBoxStyleSpinBox1::QtBoxStyleSpinBox1(QWidget *parent) # : QSpinBox(parent) # { # setFixedSize(150, 30); # setCursor(Qt::PointingHandCursor); # setAttribute(Qt::WA_MacShowFocusRect, false); # setStyleSheet(R"( # QSpinBox { # border: 1px solid lightgray; # border-radius: 3px; # } # QSpinBox::up-button { # width: 14px; # height: 14px; # margin: 0px 3px 0px -3px; # border-image: url(PATH_TO_IMG1); # } # QSpinBox::up-button:pressed { # margin-top: 1px; # } # QSpinBox::down-button { # width: 14px; # height: 14px; # margin: 0px 3px 0px -3px; # border-image: url(PATH_TO_IMG2); # } # QSpinBox::down-button:pressed { # margin-bottom: 1px; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/tablewidget/__init__.py ================================================ from .func import demo1, demo2 from .style import demo1 ================================================ FILE: src/qtbox/demo/tablewidget/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/tablewidget/func/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QTableWidget, QPushButton from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QTableWidget = createWidgetMenuBase(QTableWidget) class QtBoxFuncTableWidget1(QTableWidget): def __init__(self): super(QtBoxFuncTableWidget1, self).__init__(str(Path(__file__))) self.setFixedSize(200, 150) self.setColumnCount(3) self.setRowCount(5) self.add_btns() def add_btns(self): for row in range(self.rowCount()): for col in range(self.columnCount()): btn = QPushButton() btn.setText("button") self.setCellWidget(row, col, btn) # PyQt # PySide # from PySide2.QtWidgets import QTableWidget, QPushButton # class QtBoxFuncTableWidget1(QTableWidget): # def __init__(self): # super(QtBoxFuncTableWidget1, self).__init__() # self.setFixedSize(200, 150) # self.setColumnCount(3) # self.setRowCount(5) # self.add_btns() # def add_btns(self): # for row in range(self.rowCount()): # for col in range(self.columnCount()): # btn = QPushButton() # btn.setText("button") # self.setCellWidget(row, col, btn) # PySide # C++/Qt # #ifndef QTBOXFUNCTABLEWIDGET1_H # #define QTBOXFUNCTABLEWIDGET1_H # #include # class QtBoxFuncTableWidget1 : public QTableWidget # { # Q_OBJECT # public: # QtBoxFuncTableWidget1(QWidget *parent = nullptr); # private: # void addBtns(); # }; # #endif // QTBOXFUNCTABLEWIDGET1_H # #include "qtboxfunctablewidget1.h" # #include # QtBoxFuncTableWidget1::QtBoxFuncTableWidget1(QWidget *parent) # : QTableWidget(parent) # { # setFixedSize(200, 150); # setColumnCount(3); # setRowCount(5); # addBtns(); # } # void QtBoxFuncTableWidget1::addBtns() # { # for (int row=0; rowsetText("button"); # setCellWidget(row, col, btn); # } # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/tablewidget/func/demo2.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QTableWidget = createWidgetMenuBase(QTableWidget) class QtBoxFuncTableWidget2(QTableWidget): def __init__(self): super(QtBoxFuncTableWidget2, self).__init__(str(Path(__file__))) self.setFixedSize(200, 150) self.setColumnCount(3) self.setRowCount(5) self.set_text_and_align_center() def set_text_and_align_center(self): for row in range(self.rowCount()): for col in range(self.columnCount()): item = QTableWidgetItem() item.setText(f"{row+1}, {col+1}") item.setTextAlignment(Qt.AlignCenter) self.setItem(row, col, item) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtWidgets import QTableWidget, QTableWidgetItem # class QtBoxFuncTableWidget2(QTableWidget): # def __init__(self): # super(QtBoxFuncTableWidget2, self).__init__(str(Path(__file__))) # self.setFixedSize(200, 150) # self.setColumnCount(3) # self.setRowCount(5) # self.set_text_and_align_center() # def set_text_and_align_center(self): # for row in range(self.rowCount()): # for col in range(self.columnCount()): # item = QTableWidgetItem() # item.setText(f"{row+1}, {col+1}") # item.setTextAlignment(Qt.AlignCenter) # self.setItem(row, col, item) # PySide # C++/Qt # #ifndef QTBOXFUNCTABLEWIDGET2_H # #define QTBOXFUNCTABLEWIDGET2_H # #include # class QtBoxFuncTableWidget2 : public QTableWidget # { # Q_OBJECT # public: # QtBoxFuncTableWidget2(QWidget *parent = nullptr); # private: # void setTextAndAlignCenter(); # }; # #endif // QTBOXFUNCTABLEWIDGET2_H # #include "qtboxfunctablewidget2.h" # #include # #include # QtBoxFuncTableWidget2::QtBoxFuncTableWidget2(QWidget *parent) # : QTableWidget(parent) # { # setFixedSize(200, 150); # setColumnCount(3); # setRowCount(5); # setTextAndAlignCenter(); # } # void QtBoxFuncTableWidget2::setTextAndAlignCenter() # { # for (int row=0; rowsetText(QString("%1, %2").arg(row+1).arg(col+1)); # item->setTextAlignment(Qt::AlignCenter); # setItem(row, col, item); # } # } # } # C++/Qt ================================================ FILE: src/qtbox/demo/tablewidget/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/tablewidget/style/demo1.py ================================================ # PyQt from PyQt5.QtWidgets import QTableWidget from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QTableWidget = createWidgetMenuBase(QTableWidget) class QtBoxStyleTableWidget1(QTableWidget): def __init__(self): super(QtBoxStyleTableWidget1, self).__init__(str(Path(__file__))) self.setFixedSize(200, 150) self.setColumnCount(3) self.setRowCount(5) self.setHorizontalHeaderLabels(["A", "B", "C"]) self.setStyleSheet(""" QHeaderView::section { color: #5e5e5e; } QHeaderView::section:hover { border: none; background-color: #a2c7ae; } QHeaderView::section::horizontal:checked { border: none; border-bottom: 1px solid #3a714a; background-color: #c0daca; color: #2f5b53; } QHeaderView::section::vertical:checked { border: none; border-right: 1px solid #3a714a; background-color: #c0daca; color: #2f5b53; } QTableView { selection-background-color: transparent; selection-color: black; } QTableView::item:selected { border: 1px solid #3a714a; } """) # PyQt # PySide # from PySide2.QtWidgets import QTableWidget # class QtBoxStyleTableWidget1(QTableWidget): # def __init__(self): # super(QtBoxStyleTableWidget1, self).__init__() # self.setFixedSize(200, 150) # self.setColumnCount(3) # self.setRowCount(5) # self.setHorizontalHeaderLabels(["A", "B", "C"]) # self.setStyleSheet(""" # QHeaderView::section { # color: #5e5e5e; # } # QHeaderView::section:hover # { # border: none; # background-color: #a2c7ae; # } # QHeaderView::section::horizontal:checked # { # border: none; # border-bottom: 1px solid #3a714a; # background-color: #c0daca; # color: #2f5b53; # } # QHeaderView::section::vertical:checked # { # border: none; # border-right: 1px solid #3a714a; # background-color: #c0daca; # color: #2f5b53; # } # QTableView { # selection-background-color: transparent; # selection-color: black; # } # QTableView::item:selected { # border: 1px solid #3a714a; # } # """) # PySide # C++/Qt # #ifndef QTBOXSTYLETABLEWIDGET1_H # #define QTBOXSTYLETABLEWIDGET1_H # #include # class QtBoxStyleTableWidget1 : public QTableWidget # { # Q_OBJECT # public: # QtBoxStyleTableWidget1(QWidget *parent = nullptr); # }; # #endif // QTBOXSTYLETABLEWIDGET1_H # #include "qtboxstyletablewidget1.h" # QtBoxStyleTableWidget1::QtBoxStyleTableWidget1(QWidget *parent) # : QTableWidget(parent) # { # setFixedSize(200, 150); # setColumnCount(3); # setRowCount(5); # setHorizontalHeaderLabels({"A", "B", "C"}); # setStyleSheet(R"( # QHeaderView::section { # color: #5e5e5e; # } # QHeaderView::section:hover # { # border: none; # background-color: #a2c7ae; # } # QHeaderView::section::horizontal:checked # { # border: none; # border-bottom: 1px solid #3a714a; # background-color: #c0daca; # color: #2f5b53; # } # QHeaderView::section::vertical:checked # { # border: none; # border-right: 1px solid #3a714a; # background-color: #c0daca; # color: #2f5b53; # } # QTableView { # selection-background-color: transparent; # selection-color: black; # } # QTableView::item:selected { # border: 1px solid #3a714a; # } # )"); # } # C++/Qt ================================================ FILE: src/qtbox/demo/widget/__init__.py ================================================ from .func import demo1, demo2 from .style import demo1, demo2 ================================================ FILE: src/qtbox/demo/widget/func/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/widget/func/demo1.py ================================================ # PyQt from PyQt5.QtCore import Qt, QRect from PyQt5.QtGui import QPainter, QPen, QPalette, QColor from PyQt5.QtWidgets import QWidget from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QWidget = createWidgetMenuBase(QWidget) class QtBoxFuncWidget1(QWidget): def __init__(self): super(QtBoxFuncWidget1, self).__init__(str(Path(__file__))) self.setFixedSize(150, 150) self.rect_list = [] self.rect_start_point = None self.rect_end_point = None self.set_background_color() def set_background_color(self): palette = QPalette() palette.setColor(QPalette.Window, QColor(100, 100, 100, 255)) self.setPalette(palette) self.setAutoFillBackground(True) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.rect_start_point = event.pos() self.rect_end_point = event.pos() self.update() def mouseMoveEvent(self, event): if event.buttons() == Qt.LeftButton: self.rect_end_point = event.pos() self.update() def mouseReleaseEvent(self, event): if self.rect_start_point and self.rect_end_point: self.rect_list.append((self.rect_start_point, self.rect_end_point)) self.update() self.rect_start_point = None self.rect_end_point = None def paintEvent(self, event): super(QtBoxFuncWidget1, self).paintEvent(event) painter = QPainter(self) pen = QPen() pen.setColor(Qt.green) painter.setPen(pen) if self.rect_start_point and self.rect_end_point: painter.drawText(self.rect_start_point, f"Rect {len(self.rect_list) + 1}") rect = QRect(self.rect_start_point, self.rect_end_point) painter.drawRect(rect) for i, point_tuple in enumerate(self.rect_list): painter.drawText(point_tuple[0], f"Rect {i + 1}") rect = QRect(point_tuple[0], point_tuple[1]) painter.drawRect(rect) # PyQt # PySide # from PySide2.QtCore import Qt, QRect # from PySide2.QtGui import QPainter, QPen, QPalette, QColor # from PySide2.QtWidgets import QWidget # class QtBoxFuncWidget1(QWidget): # def __init__(self): # super(QtBoxFuncWidget1, self).__init__() # self.setFixedSize(150, 150) # self.rect_list = [] # self.rect_start_point = None # self.rect_end_point = None # self.set_background_color() # def set_background_color(self): # palette = QPalette() # palette.setColor(QPalette.Window, QColor(100, 100, 100, 255)) # self.setPalette(palette) # self.setAutoFillBackground(True) # def mousePressEvent(self, event): # if event.button() == Qt.LeftButton: # self.rect_start_point = event.pos() # self.rect_end_point = event.pos() # self.update() # def mouseMoveEvent(self, event): # if event.buttons() == Qt.LeftButton: # self.rect_end_point = event.pos() # self.update() # def mouseReleaseEvent(self, event): # if self.rect_start_point and self.rect_end_point: # self.rect_list.append((self.rect_start_point, self.rect_end_point)) # self.update() # self.rect_start_point = None # self.rect_end_point = None # def paintEvent(self, event): # super(QtBoxFuncWidget1, self).paintEvent(event) # painter = QPainter(self) # pen = QPen() # pen.setColor(Qt.green) # painter.setPen(pen) # if self.rect_start_point and self.rect_end_point: # painter.drawText(self.rect_start_point, f"Rect {len(self.rect_list) + 1}") # rect = QRect(self.rect_start_point, self.rect_end_point) # painter.drawRect(rect) # for i, point_tuple in enumerate(self.rect_list): # painter.drawText(point_tuple[0], f"Rect {i + 1}") # rect = QRect(point_tuple[0], point_tuple[1]) # painter.drawRect(rect) # PySide # C++/Qt # #ifndef QTBOXFUNCWIDGET1_H # #define QTBOXFUNCWIDGET1_H # #include # #include # #include # #include # #include # class QtBoxFuncWidget1 : public QWidget # { # Q_OBJECT # public: # QtBoxFuncWidget1(QWidget *parent = nullptr); # protected: # void mousePressEvent(QMouseEvent *event); # void mouseMoveEvent(QMouseEvent *event); # void mouseReleaseEvent(QMouseEvent *event); # void paintEvent(QPaintEvent *event); # private: # QList rectList; # QPoint rectStartPoint; # QPoint rectEndPoint; # void setBackgroundColor(); # }; # #endif // QTBOXFUNCWIDGET1_H # #include "qtboxfuncwidget1.h" # #include # #include # #include # #include # #include # QtBoxFuncWidget1::QtBoxFuncWidget1(QWidget *parent) # : QWidget(parent) # { # setFixedSize(150, 150); # setBackgroundColor(); # } # void QtBoxFuncWidget1::setBackgroundColor() # { # QPalette palette = QPalette(); # palette.setColor(QPalette::Window, QColor(100, 100, 100, 255)); # setPalette(palette); # setAutoFillBackground(true); # } # void QtBoxFuncWidget1::mousePressEvent(QMouseEvent *event) # { # if (event->button() == Qt::LeftButton) { # rectStartPoint = event->pos(); # rectEndPoint = event->pos(); # update(); # } # } # void QtBoxFuncWidget1::mouseMoveEvent(QMouseEvent *event) # { # if (event->buttons() == Qt::LeftButton) { # rectEndPoint = event->pos(); # update(); # } # } # void QtBoxFuncWidget1::mouseReleaseEvent(QMouseEvent *event) # { # if (!rectStartPoint.isNull() && !rectEndPoint.isNull()) { # QPoint *pointArray = new QPoint[2]; # pointArray[0] = rectStartPoint; # pointArray[1] = rectEndPoint; # rectList.append(pointArray); # update(); # } # rectStartPoint = QPoint(); # rectEndPoint = QPoint(); # } # void QtBoxFuncWidget1::paintEvent(QPaintEvent *event) # { # QWidget::paintEvent(event); # QPainter painter = QPainter(this); # QPen pen = QPen(); # pen.setColor(Qt::green); # painter.setPen(pen); # if (!rectStartPoint.isNull() && !rectEndPoint.isNull()) { # painter.drawText(rectStartPoint, QString("Rect %1").arg(rectList.length()+1)); # QRect rect = QRect(rectStartPoint, rectEndPoint); # painter.drawRect(rect); # } # for (int i=0; i= self.width(): is_col_drawing_stopped = True if y1 <= 0 or y2 >= self.height(): is_row_drawing_stopped = True if is_row_drawing_stopped and is_col_drawing_stopped: break line_count += 1 if line_count % 10 == 0: painter.setPen(self.dark_pen) else: painter.setPen(self.light_pen) def paintEvent(self, event): super(QtBoxFuncWidget2, self).paintEvent(event) painter = QPainter(self) self.draw_lines(painter) def resizeEvent(self, event): super(QtBoxFuncWidget2, self).resizeEvent(event) self.start_x = self.width() / 2 self.start_y = self.height() / 2 self.update() # PyQt # PySide # from PySide2.QtCore import QPointF # from PySide2.QtWidgets import QWidget # from PySide2.QtGui import QPainter, QPen, QColor # class QtBoxFuncWidget2(QWidget): # def __init__(self): # super(QtBoxFuncWidget2, self).__init__() # self.setFixedSize(150, 150) # self.line_gap = 5 # self.start_x = self.width() / 2 # self.start_y = self.height() / 2 # self.light_pen = QPen(QColor(222, 222, 222)) # self.dark_pen = QPen(QColor(222, 222, 222)) # self.dark_pen.setWidth(2) # def draw_lines(self, painter): # painter.setPen(self.dark_pen) # line_count = 0 # is_row_drawing_stopped = False # is_col_drawing_stopped = False # x1, x2 = self.start_x, self.start_x # y1, y2 = self.start_y, self.start_y # while True: # if not is_col_drawing_stopped: # painter.drawLine(QPointF(x1, 0.0), QPointF(x1, self.height())) # painter.drawLine(QPointF(x2, 0.0), QPointF(x2, self.height())) # if not is_row_drawing_stopped: # painter.drawLine(QPointF(0.0, y1), QPointF(self.width(), y1)) # painter.drawLine(QPointF(0.0, y2), QPointF(self.width(), y2)) # x1 -= self.line_gap # x2 += self.line_gap # y1 -= self.line_gap # y2 += self.line_gap # if x1 <= 0 or x2 >= self.width(): # is_col_drawing_stopped = True # if y1 <= 0 or y2 >= self.height(): # is_row_drawing_stopped = True # if is_row_drawing_stopped and is_col_drawing_stopped: # break # line_count += 1 # if line_count % 10 == 0: # painter.setPen(self.dark_pen) # else: # painter.setPen(self.light_pen) # def paintEvent(self, event): # super(QtBoxFuncWidget2, self).paintEvent(event) # painter = QPainter(self) # self.draw_lines(painter) # def resizeEvent(self, event): # super(QtBoxFuncWidget2, self).resizeEvent(event) # self.start_x = self.width() / 2 # self.start_y = self.height() / 2 # self.update() # PySide # C++/Qt # #ifndef QTBOXFUNCWIDGET2_H # #define QTBOXFUNCWIDGET2_H # #include # #include # #include # #include # #include # #include # class QtBoxFuncWidget2 : public QWidget # { # Q_OBJECT # public: # QtBoxFuncWidget2(QWidget *parent = nullptr); # protected: # void paintEvent(QPaintEvent *event); # void resizeEvent(QResizeEvent *evnet); # private: # int lineGap = 5; # float startX; # float startY; # QPen lightPen = QPen(QColor(222, 222, 222)); # QPen darkPen = QPen(QColor(222, 222, 222)); # void drawLines(QPainter &painter); # }; # #endif // QTBOXFUNCWIDGET2_H # #include "qtboxfuncwidget2.h" # #include # #include # QtBoxFuncWidget2::QtBoxFuncWidget2(QWidget *parent) # : QWidget(parent) # { # setFixedSize(150, 150); # startX = width() / 2.0; # startY = height() / 2.0; # darkPen.setWidth(2); # } # void QtBoxFuncWidget2::drawLines(QPainter &painter) # { # painter.setPen(darkPen); # int lineCount = 0; # bool isRowDrawingStopped = false; # bool isColDrawingStopped = false; # float x1 = startX; # float x2 = startX; # float y1 = startY; # float y2 = startY; # while (true){ # if (!isColDrawingStopped) { # painter.drawLine(QPointF(x1, 0.0), QPointF(x1, height())); # painter.drawLine(QPointF(x2, 0.0), QPointF(x2, height())); # } # if (!isRowDrawingStopped) { # painter.drawLine(QPointF(0.0, y1), QPointF(width(), y1)); # painter.drawLine(QPointF(0.0, y2), QPointF(width(), y2)); # } # x1 -= lineGap; # x2 += lineGap; # y1 -= lineGap; # y2 += lineGap; # if (x1 <= 0 || x2 >= width()){ # isColDrawingStopped = true; # } # if (y1 <= 0 || y2 >= height()){ # isRowDrawingStopped = true; # } # if (isRowDrawingStopped && isColDrawingStopped) { # break; # } # lineCount += 1; # if (lineCount % 10 == 0){ # painter.setPen(darkPen); # } # else { # painter.setPen(lightPen); # } # } # } # void QtBoxFuncWidget2::paintEvent(QPaintEvent *event) # { # QWidget::paintEvent(event); # QPainter painter = QPainter(this); # drawLines(painter); # } # void QtBoxFuncWidget2::resizeEvent(QResizeEvent *event) # { # QWidget::resizeEvent(event); # startX = width() / 2.0; # startY = height() / 2.0; # update(); # } # C++/Qt ================================================ FILE: src/qtbox/demo/widget/style/__init__.py ================================================ ================================================ FILE: src/qtbox/demo/widget/style/demo1.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtGui import QPainter from PyQt5.QtWidgets import QWidget from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QWidget = createWidgetMenuBase(QWidget) class QtBoxStyleWidget1(QWidget): def __init__(self): super(QtBoxStyleWidget1, self).__init__(str(Path(__file__))) self.setFixedSize(100, 100) self.setWindowFlag(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) def paintEvent(self, event): painter = QPainter(self) painter.setPen(Qt.NoPen) painter.setBrush(Qt.lightGray) painter.drawRoundedRect(self.rect(), 10, 10) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtGui import QPainter # from PySide2.QtWidgets import QWidget # class QtBoxStyleWidget1(QWidget): # def __init__(self): # super(QtBoxStyleWidget1, self).__init__() # self.setFixedSize(100, 100) # self.setWindowFlag(Qt.FramelessWindowHint) # self.setAttribute(Qt.WA_TranslucentBackground) # def paintEvent(self, event): # painter = QPainter(self) # painter.setPen(Qt.NoPen) # painter.setBrush(Qt.lightGray) # painter.drawRoundedRect(self.rect(), 10, 10) # PySide # C++/Qt # #ifndef QTBOXSTYLEWIDGET1_H # #define QTBOXSTYLEWIDGET1_H # #include # #include # class QtBoxStyleWidget1 : public QWidget # { # Q_OBJECT # public: # QtBoxStyleWidget1(QWidget *parent = nullptr); # protected: # void paintEvent(QPaintEvent *event); # }; # #endif // QTBOXSTYLEWIDGET1_H # #include "qtboxstylewidget1.h" # #include # #include # QtBoxStyleWidget1::QtBoxStyleWidget1(QWidget *parent) # : QWidget(parent) # { # setFixedSize(100, 100); # setWindowFlag(Qt::FramelessWindowHint); # setAttribute(Qt::WA_TranslucentBackground); # } # void QtBoxStyleWidget1::paintEvent(QPaintEvent *event) # { # QPainter painter = QPainter(this); # painter.setPen(Qt::NoPen); # painter.setBrush(Qt::lightGray); # painter.drawRoundedRect(rect(), 10, 10); # } # C++/Qt ================================================ FILE: src/qtbox/demo/widget/style/demo2.py ================================================ # PyQt from PyQt5.QtCore import Qt from PyQt5.QtGui import QPalette, QColor from PyQt5.QtWidgets import QWidget, QGraphicsBlurEffect from qtbox.gui.menu import createWidgetMenuBase from pathlib import Path QWidget = createWidgetMenuBase(QWidget) class QtBoxStyleWidget2(QWidget): def __init__(self): super(QtBoxStyleWidget2, self).__init__(str(Path(__file__))) self.setWindowFlag(Qt.FramelessWindowHint) self.setFixedSize(100, 100) self.set_background_color() self.blur() def set_background_color(self): palette = QPalette() palette.setColor(QPalette.Window, QColor(245, 245, 245, 220)) self.setPalette(palette) self.setAutoFillBackground(True) def blur(self): blur = QGraphicsBlurEffect() blur.setBlurRadius(10) blur.setBlurHints(QGraphicsBlurEffect.QualityHint) self.setGraphicsEffect(blur) # PyQt # PySide # from PySide2.QtCore import Qt # from PySide2.QtGui import QPalette, QColor # from PySide2.QtWidgets import QWidget, QGraphicsBlurEffect # class QtBoxStyleWidget2(QWidget): # def __init__(self): # super(QtBoxStyleWidget2, self).__init__() # self.setWindowFlag(Qt.FramelessWindowHint) # self.setFixedSize(100, 100) # self.set_background_color() # self.blur() # def set_background_color(self): # palette = QPalette() # palette.setColor(QPalette.Window, QColor(245, 245, 245, 220)) # self.setPalette(palette) # self.setAutoFillBackground(True) # def blur(self): # blur = QGraphicsBlurEffect() # blur.setBlurRadius(10) # blur.setBlurHints(QGraphicsBlurEffect.QualityHint) # self.setGraphicsEffect(blur) # PySide # C++/Qt # #ifndef QTBOXSTYLEWIDGET2_H # #define QTBOXSTYLEWIDGET2_H # #include # class QtBoxStyleWidget2 : public QWidget # { # Q_OBJECT # public: # QtBoxStyleWidget2(QWidget *parent = nullptr); # private: # void setBackgroundColor(); # void blur(); # }; # #endif // QTBOXSTYLEWIDGET2_H # #include "qtboxstylewidget2.h" # #include # #include # QtBoxStyleWidget2::QtBoxStyleWidget2(QWidget *parent) # : QWidget(parent) # { # setWindowFlag(Qt::FramelessWindowHint); # setFixedSize(100, 100); # setBackgroundColor(); # blur(); # } # void QtBoxStyleWidget2::setBackgroundColor() # { # QPalette palette = QPalette(); # palette.setColor(QPalette::Window, QColor(245, 245, 245, 220)); # setPalette(palette); # setAutoFillBackground(true); # } # void QtBoxStyleWidget2::blur() # { # QGraphicsBlurEffect *blur = new QGraphicsBlurEffect(); # blur->setBlurRadius(10); # blur->setBlurHints(QGraphicsBlurEffect::QualityHint); # setGraphicsEffect(blur); # } # C++/Qt ================================================ FILE: src/qtbox/gui/__init__.py ================================================ ================================================ FILE: src/qtbox/gui/editor.py ================================================ import sys import json from pathlib import Path from qtbox.utils.check import check_update from qtbox.utils.output import suppress_stdout_stderr from qtbox.gui.title import TitleWidget as QSSEditorTitle from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * from pygments import highlight from pygments.lexers import CssLexer from pygments.formatters import HtmlFormatter RES_PATH = Path(__file__).parent.parent / "res" with open(RES_PATH / "completion.txt", "r", encoding="utf-8") as f: COMPLETER_LIST = [keyword.strip() for keyword in f.readlines()] class LineNumberArea(QWidget): def __init__(self, parent): super(LineNumberArea, self).__init__(parent) self.parent = parent def sizeHint(self): return QSize(self.parent.get_line_number_area_width(), 0) def paintEvent(self, event): self.parent.lineNumberAreaPaintEvent(event) class CustomTextEdit(QPlainTextEdit): qss_signal = pyqtSignal(str) def __init__(self): super(CustomTextEdit, self).__init__() self.copy_btn = QPushButton() self.clipboard = QApplication.clipboard() self.line_number_area = LineNumberArea(self) self.completer = QCompleter(COMPLETER_LIST, self) self.redo_stack_list = [] self.undo_stack_list = [] self.redo_max_count = 50 self.undo_max_count = 100 self.theme = None self.set_up() def set_up(self): self.set_window_attr() self.set_object_name() self.set_style_sheet() self.set_widget() self.set_signal() self.set_layout() self.highlight_line() self.update_line_number_area_width() def set_window_attr(self): self.setMinimumWidth(200) def set_object_name(self): self.setObjectName("customEdit") self.verticalScrollBar().setObjectName("customEditVScrollBar") self.horizontalScrollBar().setObjectName("customEditHScrollBar") self.copy_btn.setObjectName("copyBtn") self.completer.popup().setObjectName("completer") def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: self.theme = json.loads(f.read())["theme"] with open(RES_PATH / f"qss/{self.theme}/editor.qss", encoding="utf-8") as f: qss_content = f.read() self.setStyleSheet(qss_content) self.completer.popup().setStyleSheet(qss_content) def set_widget(self): self.completer.setWidget(self) self.setUndoRedoEnabled(False) self.setTabStopWidth(self.fontMetrics().width("a")*4) self.copy_btn.setToolTip("Click to copy") self.copy_btn.setCursor(Qt.PointingHandCursor) self.copy_btn.setIcon(QIcon(str(RES_PATH / "images/copy.png"))) self.copy_btn.setIconSize(QSize(16, 16)) def set_signal(self): self.textChanged.connect(self.on_text_changed) self.copy_btn.clicked.connect(self.copy) self.clipboard.dataChanged.connect(self.on_clipboard_changed) self.cursorPositionChanged.connect(self.highlight_line) self.updateRequest.connect(self.update_line_number_area) self.blockCountChanged.connect(self.update_line_number_area_width) self.completer.activated.connect(self.activate_completer) def set_layout(self): h_layout = QHBoxLayout() v_layout = QVBoxLayout(self) h_layout.addStretch() h_layout.addWidget(self.copy_btn) v_layout.addLayout(h_layout) v_layout.addStretch() def on_text_changed(self): self.qss_signal.emit(self.toPlainText()) self.copy_btn.setToolTip("Click to copy") self.copy_btn.setIcon(QIcon(str(RES_PATH / "images/copy.png"))) def copy(self): self.clipboard.setText(self.toPlainText()) def on_clipboard_changed(self): data = self.clipboard.mimeData() if data.text() == self.toPlainText(): self.copy_btn.setIcon(QIcon(str(RES_PATH / "images/check.png"))) self.copy_btn.setToolTip("Copied") else: self.copy_btn.setIcon(QIcon(str(RES_PATH / "images/copy.png"))) self.copy_btn.setToolTip("Click to copy") def highlight_line(self): extra_selection_list = [] selection = QTextEdit.ExtraSelection() if self.theme == "black": selection.format.setBackground(QColor(59, 63, 66, 150)) else: selection.format.setBackground(QColor(242, 242, 242, 150)) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() extra_selection_list.append(selection) self.setExtraSelections(extra_selection_list) def get_line_number_area_width(self): offset = 10 digit_num = 3 max_value = max(1, self.blockCount()) while max_value >= 1000: max_value /= 10 digit_num += 1 width = offset + self.fontMetrics().width('9') * digit_num return width def update_line_number_area_width(self): self.setViewportMargins(self.get_line_number_area_width()-3, -4, -2, 0) def update_line_number_area(self, rect, dy): if dy: self.line_number_area.scroll(0, dy) else: self.line_number_area.update(0, rect.y(), self.line_number_area.width(), rect.height()) if rect.contains(self.viewport().rect()): self.update_line_number_area_width() def get_current_line_number(self): text_cursor = self.textCursor() return text_cursor.blockNumber() + 1 def activate_completer(self, text): completer_prefix = self.get_word_under_cursor() inserted_text = text.replace(completer_prefix, "") text_cursor = self.textCursor() text_cursor.insertText(inserted_text) current_cursor_position = text_cursor.position() self.highlight_text() new_cursor_position = text_cursor.position() self.move_back_cursor_after_highlight(current_cursor_position, new_cursor_position) def get_word_under_cursor(self): text_cursor = self.textCursor() for _ in range(text_cursor.positionInBlock()): text_cursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor) if " " in text_cursor.selectedText() or ":" in text_cursor.selectedText(): break return text_cursor.selectedText().replace(" ", "").strip() def highlight_text(self): current_plain_text = self.toPlainText().strip() if self.theme == "black": formatter = HtmlFormatter(linenos=False, style="paraiso-dark") css = "" else: formatter = HtmlFormatter(linenos=False, style="tango") css = "" html = highlight(current_plain_text, lexer=CssLexer(), formatter=formatter) self.document().setHtml(css+html) self.moveCursor(QTextCursor.End) self.add_undo_command() def move_back_cursor_after_highlight(self, pos1, pos2): # pos2-1: leave a space if pos1 < pos2-1: for _ in range(pos2-pos1): self.moveCursor(QTextCursor.Left, QTextCursor.MoveAnchor) elif pos1 > pos2: for _ in range(pos1-pos2): self.moveCursor(QTextCursor.Right, QTextCursor.MoveAnchor) def redo(self): if not self.redo_stack_list: return if self.document().toHtml() == self.redo_stack_list[-1][0]: self.redo_stack_list.pop() if not self.redo_stack_list: return redo_command = self.redo_stack_list.pop() self.document().setHtml(redo_command[0]) original_cursor_position = redo_command[1] current_cursor_position = self.textCursor().position() self.move_back_cursor_after_highlight(original_cursor_position, current_cursor_position) def add_redo_command(self, command): if len(self.redo_stack_list) > self.redo_max_count: self.redo_stack_list.pop(0) self.redo_stack_list.append(command) def undo(self): if not self.undo_stack_list: return if self.document().toHtml() == self.undo_stack_list[-1][0]: self.redo_stack_list.append(self.undo_stack_list.pop()) if not self.undo_stack_list: return undo_command = self.undo_stack_list.pop() self.add_redo_command(undo_command) self.document().setHtml(undo_command[0]) original_cursor_position = undo_command[1] current_cursor_position = self.textCursor().position() self.move_back_cursor_after_highlight(original_cursor_position, current_cursor_position) def add_undo_command(self): if len(self.undo_stack_list) > self.undo_max_count: self.undo_stack_list.pop(0) if self.undo_stack_list: if self.document().toHtml() != self.undo_stack_list[-1][0]: self.undo_stack_list.append((self.document().toHtml(), self.textCursor().position())) else: self.undo_stack_list.append((self.document().toHtml(), self.textCursor().position())) def is_text_cursor_in_brace_block(self): """Check if the text cursor is between { and }""" left_brace_pos = None right_brace_pos = None text_cursor = self.textCursor() for i in range(text_cursor.position()): text_cursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor) if "{" in text_cursor.selectedText(): left_brace_pos = i elif "}" in text_cursor.selectedText(): right_brace_pos = i if left_brace_pos is not None and right_brace_pos is not None: break if left_brace_pos is None and right_brace_pos is None: return False elif left_brace_pos is not None and right_brace_pos is None: return True elif left_brace_pos is None and right_brace_pos is not None: return False if left_brace_pos < right_brace_pos: return True else: return False def contextMenuEvent(self, event): return def resizeEvent(self, event): cr = self.contentsRect() self.line_number_area.setGeometry(QRect(cr.left(), cr.top(), self.get_line_number_area_width(), cr.height())) def keyPressEvent(self, event): if self.completer.popup().isVisible(): if event.key() == Qt.Key_Escape or event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return or event.key() == Qt.Key_Tab: event.ignore() return super(CustomTextEdit, self).keyPressEvent(event) if event.modifiers() == Qt.ControlModifier: if event.key() == Qt.Key_Z: self.undo() elif event.key() == Qt.Key_V: self.highlight_text() elif event.modifiers() == Qt.ControlModifier | Qt.ShiftModifier: if event.key() == Qt.Key_Z: self.redo() else: if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return and self.is_text_cursor_in_brace_block(): self.textCursor().insertText("\t") self.add_undo_command() word_under_cursor = self.get_word_under_cursor() if not word_under_cursor or event.key() == Qt.Key_Left or event.key() == Qt.Key_Right or event.key() == Qt.Key_Up or event.key() == Qt.Key_Down: self.completer.popup().setVisible(False) return if word_under_cursor == "{" and event.key() != Qt.Key_Backspace: self.highlight_text() return if word_under_cursor == "}" and event.key() != Qt.Key_Backspace: text_cursor = self.textCursor() for _ in range(text_cursor.positionInBlock()): text_cursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor) if text_cursor.selectedText().strip() == "}": text_cursor.removeSelectedText() text_cursor.insertText("}") self.highlight_text() return self.complete_completer(word_under_cursor) def complete_completer(self, word_under_cursor): completer_prefix = word_under_cursor self.completer.setCompletionPrefix(completer_prefix) height = 100 width = int(self.rect().width() / 2) if not self.textCursor().block().text(): x = 0 else: x = int(self.blockBoundingRect(self.textCursor().block()).width() / len(self.textCursor().block().text()) * self.textCursor().positionInBlock()) if x >= self.rect().width() - width: x = self.rect().width() - width y = self.blockBoundingGeometry(self.textCursor().block()).y() - 80 self.completer.complete(QRect(x, y, width, height)) # Select the first row by default. e = QKeyEvent(QEvent.KeyPress, Qt.Key_Down, Qt.NoModifier) QCoreApplication.postEvent(self.completer.popup(), e) def lineNumberAreaPaintEvent(self, event): painter = QPainter(self.line_number_area) if self.theme == "black": painter.fillRect(event.rect(), QColor(59, 63, 66, 150)) else: painter.fillRect(event.rect(), QColor(242, 242, 242, 150)) block = self.firstVisibleBlock() block_number = block.blockNumber() top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top() bottom = top + self.blockBoundingRect(block).height() while block.isValid() and top <= event.rect().bottom(): if block.isVisible() and bottom >= event.rect().top(): number = block_number + 1 if number == self.get_current_line_number(): painter.setPen(QColor(178, 189, 175, 250)) else: painter.setPen(QColor(178, 189, 175, 160)) text_rect = QRectF(0, top-4, self.line_number_area.width(), self.fontMetrics().height()) painter.drawText(text_rect, Qt.AlignCenter, str(number)) block = block.next() top = bottom bottom = top + self.blockBoundingRect(block).height() block_number += 1 def reload_style_sheet(self): self.set_style_sheet() self.highlight_text() class DisplayWidget(QWidget): def __init__(self): super(DisplayWidget, self).__init__() self.widget_list = ["QCheckBox", "QComboBox", "QDial", "QLabel", "QLCDNumber", "QLineEdit", "QListWidget", "QProgressBar", "QPushButton", "QRadioButton", "QSlider", "QSpinBox", "QTableWidget", "QWidget"] self.widget_combo_box = QComboBox() self.current_widget = None self.qss = None self.set_up() def set_up(self): self.set_window_attr() self.set_object_name() self.set_style_sheet() self.set_widget() self.set_signal() self.set_layout() self.change_widget("QCheckBox") def set_window_attr(self): self.setMinimumWidth(200) self.setMinimumHeight(200) def set_object_name(self): self.setObjectName("displayWidget") self.widget_combo_box.setObjectName("widgetComboBox") def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: theme = json.loads(f.read())["theme"] with open(RES_PATH / f"qss/{theme}/editor.qss", encoding="utf-8") as f: self.setStyleSheet(f.read()) icon_path = str(RES_PATH / "images/up_down.png").replace("\\", "/") self.setStyleSheet(""" QComboBox#widgetComboBox::down-arrow { width: 13px; height: 13px; image: url(%s); } """ % icon_path) def set_widget(self): self.widget_combo_box.addItems(self.widget_list) def set_signal(self): self.widget_combo_box.currentTextChanged.connect(self.change_widget) def set_layout(self): h_layout = QHBoxLayout() v_layout = QVBoxLayout(self) h_layout.addStretch() h_layout.addWidget(self.widget_combo_box) v_layout.addLayout(h_layout) v_layout.addStretch() def change_widget(self, text): if self.current_widget: self.current_widget.deleteLater() if text == "QCheckBox": self.current_widget = QCheckBox(self) self.current_widget.setText("Qt Box") self.current_widget.setTristate(True) elif text == "QComboBox": self.current_widget = QComboBox(self) self.current_widget.addItems(["1", "2", "3", "4", "5", "6"]) elif text == "QDial": self.current_widget = QDial(self) self.current_widget.setMinimum(0) self.current_widget.setMaximum(100) self.current_widget.setFixedSize(100, 100) elif text == "QLabel": self.current_widget = QLabel(self) self.current_widget.setText("Qt Box") elif text == "QLCDNumber": self.current_widget = QLCDNumber(self) self.current_widget.setDigitCount(6) self.current_widget.display(123456) elif text == "QLineEdit": self.current_widget = QLineEdit(self) self.current_widget.setPlaceholderText("Qt Box") elif text == "QListWidget": self.current_widget = QListWidget(self) self.current_widget.setFixedSize(150, 200) for i in range(5): item = QListWidgetItem() item.setText(str(i+1)) self.current_widget.addItem(item) elif text == "QProgressBar": self.current_widget = QProgressBar(self) self.current_widget.setMinimum(0) self.current_widget.setMaximum(100) self.current_widget.setValue(20) elif text == "QPushButton": self.current_widget = QPushButton(self) self.current_widget.setText("BUTTON") elif text == "QRadioButton": self.current_widget = QRadioButton(self) self.current_widget.setText("Qt Box") elif text == "QSlider": self.current_widget = QSlider(self) self.current_widget.setOrientation(Qt.Horizontal) self.current_widget.setMinimum(0) self.current_widget.setMaximum(100) elif text == "QSpinBox": self.current_widget = QSpinBox(self) elif text == "QTableWidget": self.current_widget = QTableWidget(self) self.current_widget.setFixedSize(200, 150) self.current_widget.setColumnCount(3) self.current_widget.setRowCount(5) elif text == "QWidget": self.current_widget = QWidget(self) self.current_widget.setFixedSize(150, 150) self.current_widget.setAutoFillBackground(True) if self.current_widget: self.current_widget.show() self.set_current_widget_style_sheet(self.qss) self.current_widget.move(int(self.width() / 2 - self.current_widget.width() / 2), int(self.height() / 2 - self.current_widget.height() / 2)) def set_current_widget_style_sheet(self, qss): with suppress_stdout_stderr(): self.current_widget.setStyleSheet(qss) self.qss = qss def resizeEvent(self, event): super(DisplayWidget, self).resizeEvent(event) if self.current_widget: self.current_widget.move(int(self.width()/2-self.current_widget.width()/2), int(self.height()/2-self.current_widget.height()/2)) def reload_style_sheet(self): self.set_style_sheet() class QSSEditorBody(QSplitter): def __init__(self): super(QSSEditorBody, self).__init__() self.edit = CustomTextEdit() self.display_widget = DisplayWidget() self.set_up() def set_up(self): self.set_window_attr() self.set_object_name() self.set_style_sheet() self.set_widget() self.set_signal() def set_window_attr(self): self.setMouseTracking(True) def set_object_name(self): self.setObjectName("qssEditorBody") def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: theme = json.loads(f.read())["theme"] with open(RES_PATH / f"qss/{theme}/editor.qss", encoding="utf-8") as f: self.setStyleSheet(f.read()) def set_widget(self): self.addWidget(self.edit) self.addWidget(self.display_widget) self.setSizes([400, 400]) def set_signal(self): self.edit.qss_signal.connect(self.display_widget.set_current_widget_style_sheet) def contextMenuEvent(self, event): pass def reload_style_sheet(self): self.set_style_sheet() self.edit.reload_style_sheet() self.display_widget.reload_style_sheet() class QSSEditor(QWidget): def __init__(self): super(QSSEditor, self).__init__() self.qss_editor_title = QSSEditorTitle() self.qss_editor_body = QSSEditorBody() self.start_x = None self.start_y = None self.stretch_area_offset = 10 self.is_stretching = False self.stretch_type = None self.can_stretch = False self.bg_color = None self.set_up() def set_up(self): self.set_window_attr() self.set_style_sheet() self.set_signal() self.set_layout() def set_window_attr(self): with open(RES_PATH/"config.json") as f: config = json.loads(f.read()) self.resize(config["qssEditorWidth"], config["qssEditorHeight"]) self.setMouseTracking(True) self.qss_editor_title.setMaximumHeight(40) self.setWindowFlag(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: theme = json.loads(f.read())["theme"] if theme == "black": self.bg_color = "#3b3f42" else: self.bg_color = "#f2f2f2" def set_signal(self): self.qss_editor_title.close_signal.connect(self.close) self.qss_editor_title.minimize_signal.connect(self.showMinimized) self.qss_editor_title.maximize_signal.connect(self.showMaximized) self.qss_editor_title.show_normal_signal.connect(self.showNormal) def set_layout(self): v_layout = QVBoxLayout(self) v_layout.setSpacing(0) v_layout.addWidget(self.qss_editor_title) v_layout.addWidget(self.qss_editor_body) v_layout.setSpacing(5) v_layout.setContentsMargins(0, 0, 0, 0) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: if self.can_stretch: self.is_stretching = True else: self.start_x = event.x() self.start_y = event.y() def mouseMoveEvent(self, event): if not self.is_stretching: self.check_if_can_stretch(event.x(), event.y()) if self.start_x is not None and self.start_y is not None: dis_x = event.x() - self.start_x dis_y = event.y() - self.start_y self.move(self.x() + dis_x, self.y() + dis_y) else: if self.stretch_type == "H": self.resize(event.x(), self.height()) elif self.stretch_type == "V": self.resize(self.width(), event.y()) elif self.stretch_type == "VH": self.resize(event.x(), event.y()) def mouseReleaseEvent(self, event): self.start_x = None self.start_y = None if self.is_stretching: self.is_stretching = False self.stretch_type = None self.can_stretch = False self.setCursor(Qt.ArrowCursor) self.record_size_after_stretch() def paintEvent(self, event): super(QSSEditor, self).paintEvent(event) painter = QPainter(self) painter.setPen(Qt.NoPen) painter.setBrush(QColor(self.bg_color)) painter.setRenderHint(QPainter.Antialiasing) painter.drawRoundedRect(self.rect(), 9, 9) def check_if_can_stretch(self, x, y): if x >= self.width() - self.stretch_area_offset and self.stretch_area_offset <= y <= self.height() - self.stretch_area_offset: # right border self.setCursor(Qt.SizeHorCursor) self.stretch_type = "H" self.can_stretch = True elif self.stretch_area_offset <= x <= self.width() - self.stretch_area_offset and y >= self.height() - self.stretch_area_offset: # bottom border self.setCursor(Qt.SizeVerCursor) self.stretch_type = "V" self.can_stretch = True elif x > self.width() - self.stretch_area_offset and y > self.height() - self.stretch_area_offset: # bottom right corner self.setCursor(Qt.SizeFDiagCursor) self.stretch_type = "VH" self.can_stretch = True else: self.setCursor(Qt.ArrowCursor) self.is_stretching = False self.stretch_type = None self.can_stretch = False def record_size_after_stretch(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: config = json.loads(f.read()) config["qssEditorWidth"] = self.width() config["qssEditorHeight"] = self.height() with open(RES_PATH / "config.json", "w", encoding="utf-8") as f: f.write(json.dumps(config, indent=4)) def showMaximized(self): self.move(0, 0) desktop = QApplication.desktop() self.resize(desktop.width(), desktop.height()) def showNormal(self): super(QSSEditor, self).showNormal() with open(RES_PATH/"config.json") as f: config = json.loads(f.read()) self.resize(config["qssEditorWidth"], config["qssEditorHeight"]) desktop = QApplication.desktop() self.move(desktop.width() // 2 - self.width() // 2, desktop.height() // 2 - self.height() // 2) def reload_style_sheet(self): self.set_style_sheet() self.qss_editor_title.reload_style_sheet() self.qss_editor_body.reload_style_sheet() def main(): check_update() QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) app = QApplication([]) qss_editor = QSSEditor() qss_editor.show() sys.exit(app.exec()) if __name__ == "__main__": main() ================================================ FILE: src/qtbox/gui/menu.py ================================================ import json from pathlib import Path from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * RES_PATH = Path(__file__).parent.parent / "res" class ContextMenu(QMenu): view_code_signal = pyqtSignal() download_code_signal = pyqtSignal() def __init__(self): super(ContextMenu, self).__init__() self.view_code_action = QAction(QIcon(str(RES_PATH / "images/open_eye.png")), "View Code", self) self.download_code_action = QAction(QIcon(str(RES_PATH / "images/download.png")), "Download Code", self) self.set_up() def set_up(self): self.set_action() self.set_signal() self.set_style_sheet() def set_action(self): self.addAction(self.view_code_action) self.addAction(self.download_code_action) def set_signal(self): self.view_code_action.triggered.connect(self.view_code_signal.emit) self.download_code_action.triggered.connect(self.download_code_signal.emit) def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: theme = json.loads(f.read())["theme"] with open(RES_PATH / f"qss/{theme}/menu.qss", encoding="utf-8") as f: self.setStyleSheet(f.read()) def reload_style_sheet(self): self.set_style_sheet() def createWidgetMenuBase(cls): class WidgetMenuBase(cls): view_code_signal = pyqtSignal(str) download_code_signal = pyqtSignal(str) def __init__(self, code_file_path): super(WidgetMenuBase, self).__init__() self.code_file_path = code_file_path self.context_menu = ContextMenu() def contextMenuEvent(self, event): self.context_menu.view_code_signal.connect(lambda: self.view_code_signal.emit(self.code_file_path)) self.context_menu.download_code_signal.connect(lambda: self.download_code_signal.emit(self.code_file_path)) self.context_menu.exec(event.globalPos()) return WidgetMenuBase ================================================ FILE: src/qtbox/gui/message.py ================================================ import json from pathlib import Path from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * RES_PATH = Path(__file__).parent.parent / "res" class MessageBox(QWidget): def __init__(self): super(MessageBox, self).__init__() self.title_label = QLabel() self.content_browser = QTextBrowser() self.confirm_btn = QPushButton() self.close_btn = QPushButton(self) self.start_x = None self.start_y = None self.bg_color = None self.set_up() def set_up(self): self.set_widget() self.set_signal() self.set_layout() self.set_window_attr() self.set_object_name() self.set_style_sheet() def set_widget(self): self.title_label.setAlignment(Qt.AlignCenter) self.title_label.setFixedWidth(220) self.content_browser.setMinimumHeight(300) self.confirm_btn.setText("OK") self.confirm_btn.setFixedSize(100, 30) self.close_btn.move(288, 2) self.close_btn.setFixedSize(30, 30) self.close_btn.setIcon(QIcon(str(RES_PATH / "images/close.png"))) def set_signal(self): self.close_btn.clicked.connect(self.close) self.confirm_btn.clicked.connect(self.close) def set_layout(self): all_v_layout = QVBoxLayout(self) title_h_layout = QHBoxLayout() btn_h_layout = QHBoxLayout() title_h_layout.addWidget(self.title_label) title_h_layout.setAlignment(Qt.AlignCenter) all_v_layout.addLayout(title_h_layout) all_v_layout.addSpacing(5) all_v_layout.addWidget(self.content_browser) all_v_layout.addSpacing(5) btn_h_layout.addWidget(self.confirm_btn) btn_h_layout.setAlignment(Qt.AlignCenter) all_v_layout.addLayout(btn_h_layout) def set_window_attr(self): self.setFixedSize(320, 450) self.setWindowFlag(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) def set_object_name(self): self.setObjectName("messageBox") self.title_label.setObjectName("titleLabel") self.content_browser.setObjectName("contentBrowser") self.confirm_btn.setObjectName("confirmBtn") self.close_btn.setObjectName("closeBtn") def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: theme = json.loads(f.read())["theme"] with open(RES_PATH / f"qss/{theme}/message_box.qss", encoding="utf-8") as f: self.setStyleSheet(f.read()) if theme == "black": self.bg_color = "#3b3f42" else: self.bg_color = "#f2f2f2" def mousePressEvent(self, event): pass def paintEvent(self, event): super(MessageBox, self).paintEvent(event) painter = QPainter(self) painter.setPen(Qt.NoPen) painter.setBrush(QColor(self.bg_color)) painter.setRenderHint(QPainter.Antialiasing) painter.drawRoundedRect(self.rect(), 5, 5) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.start_x = event.x() self.start_y = event.y() def mouseMoveEvent(self, event): if self.start_x is None or self.start_y is None: return dis_x = event.x() - self.start_x dis_y = event.y() - self.start_y self.move(self.x() + dis_x, self.y() + dis_y) def mouseReleaseEvent(self, event): self.start_x = None self.start_y = None def set_title(self, s): self.title_label.setText(s) def set_plain_text(self, s): self.content_browser.setPlainText(s) def set_html(self, s): self.content_browser.setHtml(s) def reload_style_sheet(self): self.set_style_sheet() ================================================ FILE: src/qtbox/gui/title.py ================================================ import json from pathlib import Path from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * RES_PATH = Path(__file__).parent.parent / "res" class TitleWidget(QWidget): close_signal = pyqtSignal() minimize_signal = pyqtSignal() maximize_signal = pyqtSignal() show_normal_signal = pyqtSignal() def __init__(self): super(TitleWidget, self).__init__() self.maximized_or_normal = "normal" self.minimize_btn = QPushButton() self.maximize_or_normal_btn = QPushButton() self.close_window_btn = QPushButton() self.set_up() def set_up(self): self.set_window_attr() self.set_object_name() self.set_style_sheet() self.set_widget() self.set_signal() self.set_layout() def set_window_attr(self): self.setMouseTracking(True) def set_object_name(self): self.setObjectName("windowTitle") self.minimize_btn.setObjectName("minimizeBtn") self.maximize_or_normal_btn.setObjectName("maximizeNormalBtn") self.close_window_btn.setObjectName("closeBtn") def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: theme = json.loads(f.read())["theme"] with open(RES_PATH / f"qss/{theme}/title.qss", encoding="utf-8") as f: self.setStyleSheet(f.read()) def set_widget(self): self.minimize_btn.setFixedSize(30, 30) self.maximize_or_normal_btn.setFixedSize(30, 30) self.close_window_btn.setFixedSize(30, 30) self.minimize_btn.setIcon(QIcon(str(RES_PATH / "images/minimize.png"))) self.maximize_or_normal_btn.setIcon(QIcon(str(RES_PATH / "images/maximize.png"))) self.close_window_btn.setIcon(QIcon(str(RES_PATH / "images/close.png"))) self.minimize_btn.setIconSize(QSize(16, 16)) self.maximize_or_normal_btn.setIconSize(QSize(16, 16)) self.close_window_btn.setIconSize(QSize(16, 16)) def set_signal(self): self.minimize_btn.clicked.connect(self.minimize) self.maximize_or_normal_btn.clicked.connect(self.maximize_or_show_normal) self.close_window_btn.clicked.connect(self.close_window) def set_layout(self): all_h_layout = QHBoxLayout(self) right_h_layout = QHBoxLayout() right_h_layout.setSpacing(0) right_h_layout.addWidget(self.minimize_btn) right_h_layout.addWidget(self.maximize_or_normal_btn) right_h_layout.addWidget(self.close_window_btn) all_h_layout.addStretch() all_h_layout.addLayout(right_h_layout) all_h_layout.setContentsMargins(5, 8, 5, 2) def minimize(self): self.minimize_signal.emit() def maximize_or_show_normal(self): if self.maximized_or_normal != "maximized": self.maximize_or_normal_btn.setIcon(QIcon(str(RES_PATH/"images/orisize.png"))) self.maximized_or_normal = "maximized" self.maximize_signal.emit() else: self.maximize_or_normal_btn.setIcon(QIcon(str(RES_PATH/"images/maximize.png"))) self.maximized_or_normal = "normal" self.show_normal_signal.emit() def close_window(self): self.close_signal.emit() def reload_style_sheet(self): self.set_style_sheet() def mouseDoubleClickEvent(self, event): super(TitleWidget, self).mouseDoubleClickEvent(event) self.maximize_or_show_normal() ================================================ FILE: src/qtbox/gui/viewer.py ================================================ import json from pathlib import Path from qtbox.gui.title import TitleWidget as CodeViewerTitle from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * from pygments import highlight from pygments.lexers import PythonLexer, CppLexer from pygments.formatters import HtmlFormatter RES_PATH = Path(__file__).parent.parent / "res" class CodeViewerBody(QTextBrowser): def __init__(self): super(CodeViewerBody, self).__init__() self.clipboard = QApplication.clipboard() self.switch_btn = QPushButton() self.copy_btn = QPushButton() self.pyside_code = "" self.pyqt_code = "" self.qt_code = "" self.code = "" self.theme = None self.set_up() def set_up(self): self.set_object_name() self.set_style_sheet() self.set_widget() self.set_signal() self.set_layout() def set_window_attr(self): self.setMouseTracking(True) def set_object_name(self): self.setObjectName("codeViewerBody") self.switch_btn.setObjectName("switchBtn") self.copy_btn.setObjectName("copyBtn") def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: self.theme = json.loads(f.read())["theme"] with open(RES_PATH / f"qss/{self.theme}/viewer.qss", encoding="utf-8") as f: self.setStyleSheet(f.read()) def set_widget(self): self.switch_btn.setToolTip("Switch to PySide") self.switch_btn.setCursor(Qt.PointingHandCursor) self.switch_btn.setIcon(QIcon(str(RES_PATH / "images/switch.png"))) self.switch_btn.setIconSize(QSize(16, 16)) self.copy_btn.setToolTip("Click to copy") self.copy_btn.setCursor(Qt.PointingHandCursor) self.copy_btn.setIcon(QIcon(str(RES_PATH / "images/copy.png"))) self.copy_btn.setIconSize(QSize(16, 16)) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) def set_signal(self): self.copy_btn.clicked.connect(self.copy) self.switch_btn.clicked.connect(self.switch_code) self.clipboard.dataChanged.connect(self.on_clipboard_changed) def set_layout(self): h_layout = QHBoxLayout() v_layout = QVBoxLayout(self) h_layout.addStretch() h_layout.addWidget(self.switch_btn) h_layout.addWidget(self.copy_btn) v_layout.addLayout(h_layout) v_layout.addStretch() def set_code(self, code): self.code = code if self.theme == "black": formatter = HtmlFormatter(linenos=True, style="paraiso-dark") css = "" else: formatter = HtmlFormatter(linenos=True, style="tango") css = "" lexer = CppLexer() if self.switch_btn.toolTip() == "Switch to PyQt" else PythonLexer() html = highlight(self.code, lexer=lexer, formatter=formatter) self.setHtml(css+html) self.horizontalScrollBar().move(0, 0) self.copy_btn.setIcon(QIcon(str(RES_PATH / "images/copy.png"))) self.copy_btn.setToolTip("Click to copy") def copy(self): self.clipboard.setText(self.code) def on_clipboard_changed(self): data = self.clipboard.mimeData() if data.text() == self.code: self.copy_btn.setIcon(QIcon(str(RES_PATH / "images/check.png"))) self.copy_btn.setToolTip("Copied") else: self.copy_btn.setIcon(QIcon(str(RES_PATH / "images/copy.png"))) self.copy_btn.setToolTip("Click to copy") def contextMenuEvent(self, event): pass def switch_code(self): if self.switch_btn.toolTip() == "Switch to PySide": self.switch_btn.setToolTip("Switch to Qt") self.set_code(self.pyside_code) elif self.switch_btn.toolTip() == "Switch to Qt": self.switch_btn.setToolTip("Switch to PyQt") self.set_code(self.qt_code) else: self.switch_btn.setToolTip("Switch to PySide") self.set_code(self.pyqt_code) def reload_style_sheet(self): self.set_style_sheet() class CodeViewer(QWidget): def __init__(self): super(CodeViewer, self).__init__() self.code_viewer_title = CodeViewerTitle() self.code_viewer_body = CodeViewerBody() self.start_x = None self.start_y = None self.stretch_area_offset = 10 self.is_stretching = False self.stretch_type = None self.can_stretch = False self.bg_color = None self.set_up() def set_up(self): self.set_window_attr() self.set_style_sheet() self.set_signal() self.set_layout() def set_window_attr(self): with open(RES_PATH/"config.json") as f: config = json.loads(f.read()) self.resize(config["codeViewerWidth"], config["codeViewerHeight"]) self.setMouseTracking(True) self.setWindowFlag(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: theme = json.loads(f.read())["theme"] if theme == "black": self.bg_color = "#3b3f42" else: self.bg_color = "#f2f2f2" def set_signal(self): self.code_viewer_title.close_signal.connect(self.close) self.code_viewer_title.minimize_signal.connect(self.showMinimized) self.code_viewer_title.maximize_signal.connect(self.showMaximized) self.code_viewer_title.show_normal_signal.connect(self.showNormal) def set_layout(self): v_layout = QVBoxLayout(self) v_layout.setSpacing(0) v_layout.addWidget(self.code_viewer_title) v_layout.addWidget(self.code_viewer_body) v_layout.setSpacing(5) v_layout.setContentsMargins(0, 0, 0, 0) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: if self.can_stretch: self.is_stretching = True else: self.start_x = event.x() self.start_y = event.y() def mouseMoveEvent(self, event): if not self.is_stretching: self.check_if_can_stretch(event.x(), event.y()) if self.start_x is not None and self.start_y is not None: dis_x = event.x() - self.start_x dis_y = event.y() - self.start_y self.move(self.x() + dis_x, self.y() + dis_y) else: if self.stretch_type == "H": self.resize(event.x(), self.height()) elif self.stretch_type == "V": self.resize(self.width(), event.y()) elif self.stretch_type == "VH": self.resize(event.x(), event.y()) def mouseReleaseEvent(self, event): self.start_x = None self.start_y = None if self.is_stretching: self.is_stretching = False self.stretch_type = None self.can_stretch = False self.setCursor(Qt.ArrowCursor) self.record_size_after_stretch() def paintEvent(self, event): super(CodeViewer, self).paintEvent(event) painter = QPainter(self) painter.setPen(Qt.NoPen) painter.setBrush(QColor(self.bg_color)) painter.setRenderHint(QPainter.Antialiasing) painter.drawRoundedRect(self.rect(), 9, 9) def check_if_can_stretch(self, x, y): if x >= self.width() - self.stretch_area_offset and self.stretch_area_offset <= y <= self.height() - self.stretch_area_offset: # right border self.setCursor(Qt.SizeHorCursor) self.stretch_type = "H" self.can_stretch = True elif self.stretch_area_offset <= x <= self.width() - self.stretch_area_offset and y >= self.height() - self.stretch_area_offset: # bottom border self.setCursor(Qt.SizeVerCursor) self.stretch_type = "V" self.can_stretch = True elif x > self.width() - self.stretch_area_offset and y > self.height() - self.stretch_area_offset: # bottom right corner self.setCursor(Qt.SizeFDiagCursor) self.stretch_type = "VH" self.can_stretch = True else: self.setCursor(Qt.ArrowCursor) self.is_stretching = False self.stretch_type = None self.can_stretch = False def record_size_after_stretch(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: config = json.loads(f.read()) config["codeViewerWidth"] = self.width() config["codeViewerHeight"] = self.height() with open(RES_PATH / "config.json", "w", encoding="utf-8") as f: f.write(json.dumps(config, indent=4)) def showMaximized(self): self.move(0, 0) desktop = QApplication.desktop() self.resize(desktop.width(), desktop.height()) def showNormal(self): super(CodeViewer, self).showNormal() with open(RES_PATH/"config.json") as f: config = json.loads(f.read()) self.resize(config["codeViewerWidth"], config["codeViewerHeight"]) desktop = QApplication.desktop() self.move(desktop.width() // 2 - self.width() // 2, desktop.height() // 2 - self.height() // 2) def assign_code(self, pyqt_code, pyside_code, qt_code): self.code_viewer_body.pyqt_code = pyqt_code self.code_viewer_body.pyside_code = pyside_code self.code_viewer_body.qt_code = qt_code def set_code(self, code): self.code_viewer_body.set_code(code) def reload_style_sheet(self): self.set_style_sheet() self.code_viewer_title.reload_style_sheet() self.code_viewer_body.reload_style_sheet() self.code_viewer_body.set_code(self.code_viewer_body.code) ================================================ FILE: src/qtbox/gui/window.py ================================================ import re import json import webbrowser from pathlib import Path from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * from qtbox.gui.editor import QSSEditor from qtbox.gui.viewer import CodeViewer from qtbox.gui.message import MessageBox from qtbox.gui.title import TitleWidget as WindowTitle from qtbox.demo.checkbox import func as func_checkbox from qtbox.demo.checkbox import style as style_checkbox from qtbox.demo.combobox import func as func_combobox from qtbox.demo.combobox import style as style_combobox from qtbox.demo.dial import func as func_dial from qtbox.demo.dial import style as style_dial from qtbox.demo.label import func as func_label from qtbox.demo.label import style as style_label from qtbox.demo.lcdnumber import func as func_lcdnumber from qtbox.demo.lcdnumber import style as style_lcdnumber from qtbox.demo.lineedit import func as func_lineedit from qtbox.demo.lineedit import style as style_lineedit from qtbox.demo.listwidget import func as func_listwidget from qtbox.demo.listwidget import style as style_listwidget from qtbox.demo.progressbar import func as func_progressbar from qtbox.demo.progressbar import style as style_progressbar from qtbox.demo.pushbutton import func as func_pushbutton from qtbox.demo.pushbutton import style as style_pushbutton from qtbox.demo.slider import func as func_slider from qtbox.demo.slider import style as style_slider from qtbox.demo.spinbox import func as func_spinbox from qtbox.demo.spinbox import style as style_spinbox from qtbox.demo.tablewidget import func as func_tablewidget from qtbox.demo.tablewidget import style as style_tablewidget from qtbox.demo.widget import func as func_widget from qtbox.demo.widget import style as style_widget VERSION = "1.2.0" UPDATES = """ 1. Fixed known bugs.\n 2. Updated the project structure. \n 3. Added C++/Qt code for each demo. \n 4. Adapted to high resolution screen. Thank @panhaovue for the tip. \n """ RES_PATH = Path(__file__).parent.parent / "res" class WindowBody(QWidget): switch_theme_signal = pyqtSignal() def __init__(self): super(WindowBody, self).__init__() self.btn_list_widget = QListWidget() self.btn_list = [QPushButton(txt) for txt in ["QCheckBox", "QComboBox", "QDial", "QLabel", "QLCDNumber", "QLineEdit", "QListWidget", "QProgressBar", "QPushButton", "QSlider", "QSpinBox", "QTableWidget", "QWidget"]] self.func_widget = QWidget() self.style_widget = QWidget() self.func_tab = QScrollArea() self.style_tab = QScrollArea() self.tab_widget = QTabWidget() self.editor_btn = QPushButton() self.sponsor_btn = QPushButton() self.doc_btn = QPushButton() self.about_btn = QPushButton() self.switch_btn = QPushButton() self.qss_editor = QSSEditor() self.code_viewer = CodeViewer() self.updates_message_box = MessageBox() self.sponsor_message_box = MessageBox() self.grid_layout_children = [] self.grid_layout = QGridLayout() self.checkbox_dict = { "func": [func_checkbox.demo1.QtBoxFuncCheckBox1, func_checkbox.demo2.QtBoxFuncCheckBox2], "style": [style_checkbox.demo1.QtBoxStyleCheckBox1, style_checkbox.demo2.QtBoxStyleCheckBox2, style_checkbox.demo3.QtBoxStyleCheckBox3, style_checkbox.demo4.QtBoxStyleCheckBox4] } self.combobox_dict = { "func": [func_combobox.demo1.QtBoxFuncComboBox1, func_combobox.demo2.QtBoxFuncComboBox2], "style": [style_combobox.demo1.QtBoxStyleComboBox1, style_combobox.demo2.QtBoxStyleComboBox2, style_combobox.demo3.QtBoxStyleComboBox3] } self.dial_dict = { "func": [func_dial.demo1.QtBoxFuncDial1], "style": [style_dial.demo1.QtBoxStyleDial1, style_dial.demo2.QtBoxStyleDial2] } self.label_dict = { "func": [func_label.demo1.QtBoxFuncLabel1, func_label.demo2.QtBoxFuncLabel2, func_label.demo3.QtBoxFuncLabel3, func_label.demo4.QtBoxFuncLabel4, func_label.demo5.QtBoxFuncLabel5, func_label.demo6.QtBoxFuncLabel6, func_label.demo7.QtBoxFuncLabel7], "style": [style_label.demo1.QtBoxStyleLabel1, style_label.demo2.QtBoxStyleLabel2, style_label.demo3.QtBoxStyleLabel3, style_label.demo4.QtBoxStyleLabel4] } self.lcdnumber_dict = { "func": [func_lcdnumber.demo1.QtBoxFuncLCDNumber1, func_lcdnumber.demo2.QtBoxFuncLCDNumber2, func_lcdnumber.demo3.QtBoxFuncLCDNumber3], "style": [style_lcdnumber.demo1.QtBoxStyleLCDNumber1, style_lcdnumber.demo2.QtBoxStyleLCDNumber2, style_lcdnumber.demo3.QtBoxStyleLCDNumber3, style_lcdnumber.demo4.QtBoxStyleLCDNumber4, style_lcdnumber.demo5.QtBoxStyleLCDNumber5] } self.lineedit_dict = { "func": [func_lineedit.demo1.QtBoxFuncLineEdit1, func_lineedit.demo2.QtBoxFuncLineEdit2, func_lineedit.demo3.QtBoxFuncLineEdit3, func_lineedit.demo4.QtBoxFuncLineEdit4, func_lineedit.demo5.QtBoxFuncLineEdit5], "style": [style_lineedit.demo1.QtBoxStyleLineEdit1, style_lineedit.demo2.QtBoxStyleLineEdit2, style_lineedit.demo3.QtBoxStyleLineEdit3, style_lineedit.demo4.QtBoxStyleLineEdit4, style_lineedit.demo5.QtBoxStyleLineEdit5, style_lineedit.demo6.QtBoxStyleLineEdit6, style_lineedit.demo7.QtBoxStyleLineEdit7] } self.listwidget_dict = { "func": [func_listwidget.demo1.QtBoxFuncListWidget1], "style": [style_listwidget.demo1.QtBoxStyleListWidget1, style_listwidget.demo2.QtBoxStyleListWidget2] } self.progressbar_dict = { "func": [func_progressbar.demo1.QtBoxFuncProgressBar1, func_progressbar.demo2.QtBoxFuncProgressBar2], "style": [style_progressbar.demo1.QtBoxStyleProgressBar1, style_progressbar.demo2.QtBoxStyleProgressBar2, style_progressbar.demo3.QtBoxStyleProgressBar3, style_progressbar.demo4.QtBoxStyleProgressBar4, style_progressbar.demo5.QtBoxStyleProgressBar5, style_progressbar.demo6.QtBoxStyleProgressBar6, style_progressbar.demo7.QtBoxStyleProgressBar7, style_progressbar.demo8.QtBoxStyleProgressBar8, style_progressbar.demo9.QtBoxStyleProgressBar9] } self.pushbutton_dict = { "func": [func_pushbutton.demo1.QtBoxFuncButton1, func_pushbutton.demo2.QtBoxFuncButton2, func_pushbutton.demo3.QtBoxFuncButton3], "style": [style_pushbutton.demo1.QtBoxStyleButton1, style_pushbutton.demo2.QtBoxStyleButton2, style_pushbutton.demo3.QtBoxStyleButton3, style_pushbutton.demo4.QtBoxStyleButton4, style_pushbutton.demo5.QtBoxStyleButton5, style_pushbutton.demo6.QtBoxStyleButton6, style_pushbutton.demo7.QtBoxStyleButton7, style_pushbutton.demo8.QtBoxStyleButton8, style_pushbutton.demo9.QtBoxStyleButton9, style_pushbutton.demo10.QtBoxStyleButton10, style_pushbutton.demo11.QtBoxStyleButton11, style_pushbutton.demo12.QtBoxStyleButton12] } self.slider_dict = { "func": [func_slider.demo1.QtBoxFuncSlider1], "style": [style_slider.demo1.QtBoxStyleSlider1, style_slider.demo2.QtBoxStyleSlider2, style_slider.demo3.QtBoxStyleSlider3, style_slider.demo4.QtBoxStyleSlider4, style_slider.demo5.QtBoxStyleSlider5] } self.spinbox_dict = { "func": [func_spinbox.demo1.QtBoxFuncSpinBox1], "style": [style_spinbox.demo1.QtBoxStyleSpinBox1] } self.tablewidget_dict = { "func": [func_tablewidget.demo1.QtBoxFuncTableWidget1, func_tablewidget.demo2.QtBoxFuncTableWidget2], "style": [style_tablewidget.demo1.QtBoxStyleTableWidget1] } self.widget_dict = { "func": [func_widget.demo1.QtBoxFuncWidget1, func_widget.demo2.QtBoxFuncWidget2], "style": [style_widget.demo1.QtBoxStyleWidget1, style_widget.demo2.QtBoxStyleWidget2] } self.set_up() def set_up(self): self.set_window_attr() self.set_object_name() self.set_style_sheet() self.set_widget() self.set_signal() self.set_layout() self.btn_list[0].setCheckable(True) self.btn_list[0].setChecked(True) self.set_tab_content("QCheckBox") def set_window_attr(self): self.setMouseTracking(True) def set_object_name(self): self.setObjectName("windowBody") self.btn_list_widget.setObjectName("btnList") self.btn_list_widget.verticalScrollBar().setObjectName("btnList") for btn in self.btn_list: btn.setObjectName("listBtn") self.editor_btn.setObjectName("editorBtn") self.sponsor_btn.setObjectName("sponsorBtn") self.doc_btn.setObjectName("docBtn") self.about_btn.setObjectName("aboutBtn") self.switch_btn.setObjectName("switchBtn") self.tab_widget.setObjectName("tabWidget") self.func_tab.setObjectName("funcScrollArea") self.style_tab.setObjectName("styleScrollArea") self.func_tab.verticalScrollBar().setObjectName("funcScrollVBar") self.func_tab.horizontalScrollBar().setObjectName("funcScrollHBar") self.style_tab.verticalScrollBar().setObjectName("styleScrollVBar") self.style_tab.horizontalScrollBar().setObjectName("styleScrollHBar") self.func_widget.setObjectName("funcWidget") self.style_widget.setObjectName("styleWidget") def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: theme = json.loads(f.read())["theme"] with open(RES_PATH / f"qss/{theme}/window_body.qss", encoding="utf-8") as f: self.setStyleSheet(f.read()) def set_widget(self): self.btn_list_widget.setMaximumWidth(300) self.btn_list_widget.setMinimumWidth(150) self.func_tab.setWidgetResizable(True) self.style_tab.setWidgetResizable(True) self.func_tab.setWidget(self.func_widget) self.style_tab.setWidget(self.style_widget) self.func_tab.setAlignment(Qt.AlignCenter) self.style_tab.setAlignment(Qt.AlignCenter) self.tab_widget.addTab(self.style_tab, "Style") self.tab_widget.addTab(self.func_tab, "Function") self.editor_btn.setFixedWidth(30) self.sponsor_btn.setFixedWidth(30) self.doc_btn.setFixedWidth(30) self.about_btn.setFixedWidth(30) self.switch_btn.setFixedWidth(30) self.editor_btn.setIconSize(QSize(16, 16)) self.sponsor_btn.setIconSize(QSize(16, 16)) self.doc_btn.setIconSize(QSize(16, 16)) self.about_btn.setIconSize(QSize(16, 16)) self.switch_btn.setIconSize(QSize(16, 16)) self.editor_btn.setToolTip("Open QSS editor") self.sponsor_btn.setToolTip("Sponsor") self.doc_btn.setToolTip("Open documentation") self.about_btn.setToolTip("Show updates") self.switch_btn.setToolTip("Switch theme") self.editor_btn.setCursor(Qt.PointingHandCursor) self.sponsor_btn.setCursor(Qt.PointingHandCursor) self.doc_btn.setCursor(Qt.PointingHandCursor) self.about_btn.setCursor(Qt.PointingHandCursor) self.switch_btn.setCursor(Qt.PointingHandCursor) self.editor_btn.setIcon(QIcon(str(RES_PATH / "images/editor.png"))) self.sponsor_btn.setIcon(QIcon(str(RES_PATH / "images/sponsor.png"))) self.doc_btn.setIcon(QIcon(str(RES_PATH / "images/doc.png"))) self.about_btn.setIcon(QIcon(str(RES_PATH / "images/about.png"))) self.switch_btn.setIcon(QIcon(str(RES_PATH / "images/switch.png"))) self.code_viewer.hide() desktop = QApplication.desktop() self.updates_message_box.move(desktop.width()//2-self.updates_message_box.width()//2, desktop.height()//2-self.updates_message_box.height()//2) self.updates_message_box.set_title(f"Qt Box Updates v{VERSION}") self.updates_message_box.set_plain_text(UPDATES) self.updates_message_box.content_browser.setLineWrapMode(QTextEdit.NoWrap) self.updates_message_box.hide() self.sponsor_message_box.setFixedSize(320, 205) self.sponsor_message_box.content_browser.setMinimumHeight(95) self.sponsor_message_box.move(desktop.width()//2-self.sponsor_message_box.width()//2, desktop.height()//2-self.sponsor_message_box.height()//2) self.sponsor_message_box.set_title("Customize") self.sponsor_message_box.set_html("Contact louasure@126.com to customize a widget. If you have any problems with PyQt or PySide, you may contact me, too. I will be very happy to provide solutions. Sponsors' needs will be treated with top priority. (๑•̀ㅂ•́)و✧") self.sponsor_message_box.content_browser.setOpenExternalLinks(True) self.sponsor_message_box.content_browser.setAlignment(Qt.AlignJustify) self.sponsor_message_box.hide() def set_signal(self): for btn in self.btn_list: btn.clicked.connect(self.change_widget) self.editor_btn.clicked.connect(self.open_editor) self.sponsor_btn.clicked.connect(self.show_sponsor_message) self.doc_btn.clicked.connect(self.open_doc) self.about_btn.clicked.connect(self.show_updates) self.switch_btn.clicked.connect(self.switch_theme) self.tab_widget.currentChanged.connect(self.change_tab) def set_layout(self): v_layout1 = QVBoxLayout() h_layout1 = QHBoxLayout() h_layout2 = QHBoxLayout() v_layout1.setContentsMargins(0, 0, 0, 0) h_layout1.setContentsMargins(0, 0, 0, 0) for btn in self.btn_list: item = QListWidgetItem() item.setSizeHint(QSize(150, 50)) self.btn_list_widget.addItem(item) self.btn_list_widget.setItemWidget(item, btn) h_layout1.addWidget(self.editor_btn) h_layout1.addWidget(self.sponsor_btn) h_layout1.addWidget(self.doc_btn) h_layout1.addWidget(self.about_btn) h_layout1.addWidget(self.switch_btn) h_layout1.setSpacing(30) v_layout1.addLayout(h_layout1) v_layout1.addWidget(self.btn_list_widget) v_layout1.setSpacing(6) h_layout2.addLayout(v_layout1) h_layout2.addWidget(self.tab_widget) self.setLayout(h_layout2) self.grid_layout.setVerticalSpacing(70) self.grid_layout.setHorizontalSpacing(60) def change_widget(self): self.update_btn_style() self.clear_grid_layout() self.set_tab_content(self.sender().text()) def change_tab(self): """change between Style and Function tab""" self.clear_grid_layout() for btn in self.btn_list: if btn.isChecked(): self.set_tab_content(btn.text()) break def update_btn_style(self): for btn in self.btn_list: btn.setCheckable(False) btn.setChecked(False) self.sender().setCheckable(True) self.sender().setChecked(True) self.btn_list_widget.update() def clear_grid_layout(self): for widget in self.grid_layout_children: widget.deleteLater() self.grid_layout_children = [] self.tab_widget.update() def set_tab_content(self, btn_txt): widget_list = [] tab_index = self.tab_widget.currentIndex() key = "style" if tab_index == 0 else "func" if btn_txt == "QComboBox": widget_list = self.combobox_dict[key] elif btn_txt == "QCheckBox": widget_list = self.checkbox_dict[key] elif btn_txt == "QDial": widget_list = self.dial_dict[key] elif btn_txt == "QLabel": widget_list = self.label_dict[key] elif btn_txt == "QLCDNumber": widget_list = self.lcdnumber_dict[key] elif btn_txt == "QLineEdit": widget_list = self.lineedit_dict[key] elif btn_txt == "QListWidget": widget_list = self.listwidget_dict[key] elif btn_txt == "QProgressBar": widget_list = self.progressbar_dict[key] elif btn_txt == "QPushButton": widget_list = self.pushbutton_dict[key] elif btn_txt == "QSlider": widget_list = self.slider_dict[key] elif btn_txt == "QSpinBox": widget_list = self.spinbox_dict[key] elif btn_txt == "QTableWidget": widget_list = self.tablewidget_dict[key] elif btn_txt == "QWidget": widget_list = self.widget_dict[key] if tab_index == 0: self.set_style_tab_content(widget_list) else: self.set_func_tab_content(widget_list) def set_style_tab_content(self, widget_list): self.add_widget_list_to_grid_layout(widget_list) self.style_widget.setLayout(self.grid_layout) def set_func_tab_content(self, widget_list): self.add_widget_list_to_grid_layout(widget_list) self.func_widget.setLayout(self.grid_layout) def add_widget_list_to_grid_layout(self, widget_list): row, column = 0, 0 for widget in widget_list: if column != 0 and column % 3 == 0: row += 1 column = 0 widget = widget() widget.view_code_signal.connect(self.view_code) widget.download_code_signal.connect(self.download_code) self.grid_layout.addWidget(widget, row, column, 1, 1, Qt.AlignCenter) self.grid_layout_children.append(widget) column += 1 def view_code(self, code_file_path): pyqt_code, pyside_code, qt_code = self.get_code_content(code_file_path) self.code_viewer.assign_code(pyqt_code, pyside_code, qt_code) self.code_viewer.set_code(pyqt_code) self.code_viewer.show() self.code_viewer.raise_() def download_code(self, code_file_path): path = QFileDialog.getExistingDirectory(self, "Open Directory", "./", QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) if not path: return pyqt_code, pyside_code, qt_code = self.get_code_content(code_file_path) with open(path+"/pyqt_code.py", "w", encoding="utf-8") as f: f.write(pyqt_code) with open(path+"/pyside_code.py", "w", encoding="utf-8") as f: f.write(pyside_code) with open(path + "/qt_code.h", "w", encoding="utf-8") as f: f.write(qt_code.split("\n\n\n")[0].strip()) with open(path+"/qt_code.cpp", "w", encoding="utf-8") as f: f.write(qt_code.split("\n\n\n")[1].strip()) @staticmethod def get_code_content(code_file_path): content = "" with open(code_file_path, "r", encoding="utf-8") as f: for line in f.readlines(): if "pathlib" not in line and "Base" not in line and '"res/images' not in line: content += line content = content.replace("str(Path(__file__))", "").replace("%s", "PATH_TO_IMG") content = re.sub(r" % \(.+\)", ")", content) try: pyqt_code = re.search(r"# PyQt.+# PyQt", content, re.DOTALL).group().replace("# PyQt\n", "").replace("# PyQt", "") except AttributeError: pyqt_code = "" try: pyside_code = re.search(r"# PySide.+# PySide", content, re.DOTALL).group().replace("# PySide\n", "").replace("# PySide", "").replace("# ", "") except AttributeError: pyside_code = "" try: qt_code = re.search(r"# C\+\+/Qt.+# C\+\+/Qt", content, re.DOTALL).group().replace("# C++/Qt\n", "").replace("# C++/Qt", "").replace("# ", "") except AttributeError: qt_code = "" return pyqt_code, pyside_code, qt_code def open_editor(self): self.qss_editor.show() def show_sponsor_message(self): self.sponsor_message_box.show() self.sponsor_message_box.raise_() @staticmethod def open_doc(): webbrowser.open("https://github.com/la-vie-est-belle/qtbox") def show_updates(self): self.updates_message_box.show() self.updates_message_box.raise_() def switch_theme(self): self.switch_theme_signal.emit() def reload_style_sheet(self): self.set_style_sheet() self.qss_editor.reload_style_sheet() self.code_viewer.reload_style_sheet() self.updates_message_box.reload_style_sheet() self.sponsor_message_box.reload_style_sheet() for widget in self.grid_layout_children: widget.context_menu.reload_style_sheet() class Window(QWidget): def __init__(self): super(Window, self).__init__() self.window_title = WindowTitle() self.window_body = WindowBody() self.start_x = None self.start_y = None self.stretch_area_offset = 10 self.is_stretching = False self.stretch_type = None self.can_stretch = False self.bg_color = None self.set_up() def set_up(self): self.set_window_attr() self.set_object_name() self.set_style_sheet() self.set_signal() self.set_layout() def set_window_attr(self): with open(RES_PATH/"config.json") as f: config = json.loads(f.read()) self.resize(config["mainWindowWidth"], config["mainWindowHeight"]) self.setMouseTracking(True) self.setWindowTitle("Qt Box") self.setWindowFlag(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) self.setWindowIcon(QIcon(str(RES_PATH / "images/icon.png"))) def set_object_name(self): self.setObjectName("window") def set_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: theme = json.loads(f.read())["theme"] if theme == "black": self.bg_color = "#3b3f42" else: self.bg_color = "#f2f2f2" def set_signal(self): self.window_title.close_signal.connect(self.close) self.window_title.minimize_signal.connect(self.showMinimized) self.window_title.maximize_signal.connect(self.showMaximized) self.window_title.show_normal_signal.connect(self.showNormal) self.window_body.switch_theme_signal.connect(self.reload_style_sheet) def set_layout(self): v_layout = QVBoxLayout(self) v_layout.setSpacing(0) v_layout.addWidget(self.window_title) v_layout.addWidget(self.window_body) v_layout.setContentsMargins(0, 0, 0, 0) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: if self.can_stretch: self.is_stretching = True else: self.start_x = event.x() self.start_y = event.y() def mouseMoveEvent(self, event): if not self.is_stretching: self.check_if_can_stretch(event.x(), event.y()) if self.start_x is not None and self.start_y is not None: dis_x = event.x() - self.start_x dis_y = event.y() - self.start_y self.move(self.x() + dis_x, self.y() + dis_y) else: if self.stretch_type == "H": self.resize(event.x(), self.height()) elif self.stretch_type == "V": self.resize(self.width(), event.y()) elif self.stretch_type == "VH": self.resize(event.x(), event.y()) def mouseReleaseEvent(self, event): self.start_x = None self.start_y = None if self.is_stretching: self.is_stretching = False self.stretch_type = None self.can_stretch = False self.setCursor(Qt.ArrowCursor) self.record_size_after_stretch() def paintEvent(self, event): super(Window, self).paintEvent(event) painter = QPainter(self) painter.setPen(Qt.NoPen) painter.setBrush(QColor(self.bg_color)) painter.setRenderHint(QPainter.Antialiasing) painter.drawRoundedRect(self.rect(), 9, 9) def check_if_can_stretch(self, x, y): if x >= self.width() - self.stretch_area_offset and self.stretch_area_offset <= y <= self.height() - self.stretch_area_offset: # right border self.setCursor(Qt.SizeHorCursor) self.stretch_type = "H" self.can_stretch = True elif self.stretch_area_offset <= x <= self.width() - self.stretch_area_offset and y >= self.height() - self.stretch_area_offset: # bottom border self.setCursor(Qt.SizeVerCursor) self.stretch_type = "V" self.can_stretch = True elif x > self.width() - self.stretch_area_offset and y > self.height() - self.stretch_area_offset: # bottom right corner self.setCursor(Qt.SizeFDiagCursor) self.stretch_type = "VH" self.can_stretch = True else: self.setCursor(Qt.ArrowCursor) self.is_stretching = False self.stretch_type = None self.can_stretch = False def record_size_after_stretch(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: config = json.loads(f.read()) config["mainWindowWidth"] = self.width() config["mainWindowHeight"] = self.height() with open(RES_PATH / "config.json", "w", encoding="utf-8") as f: f.write(json.dumps(config, indent=4)) def showMaximized(self): self.move(0, 0) desktop = QApplication.desktop() self.resize(desktop.width(), desktop.height()) def showNormal(self): super(Window, self).showNormal() with open(RES_PATH/"config.json") as f: config = json.loads(f.read()) self.resize(config["mainWindowWidth"], config["mainWindowHeight"]) desktop = QApplication.desktop() self.move(desktop.width() // 2 - self.width() // 2, desktop.height() // 2 - self.height() // 2) def reload_style_sheet(self): with open(RES_PATH / "config.json", "r", encoding="utf-8") as f: config = json.loads(f.read()) if config["theme"] == "black": config["theme"] = "white" else: config["theme"] = "black" with open(RES_PATH / "config.json", "w", encoding="utf-8") as f: f.write(json.dumps(config, indent=4)) self.set_style_sheet() self.window_title.reload_style_sheet() self.window_body.reload_style_sheet() ================================================ FILE: src/qtbox/main.py ================================================ import sys from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * from qtbox.gui.window import Window from qtbox.utils.check import check_update def main(): check_update() QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) app = QApplication([]) window = Window() window.show() sys.exit(app.exec()) if __name__ == "__main__": main() ================================================ FILE: src/qtbox/res/completion.txt ================================================ -qt-background-role -qt-style-features ::add-line ::add-page ::branch ::chunk ::close-button ::corner ::down-arrow ::down-button ::drop-down ::float-button ::groove ::handle ::icon ::indicator ::item ::left-arrow ::left-corner ::menu-arrow ::menu-button ::menu-indicator ::pane ::right-arrow ::right-corner ::scroller ::section ::separator ::sub-line ::sub-page ::tab ::tab-bar ::tear ::tearoff ::text ::title ::up-arrow ::up-button :active :adjoins-item :alternate :bottom :checked :closable :closed :default :disabled :edit-focus :editable :enabled :exclusive :first :flat :floatable :focus :has-children :has-siblings :horizontal :hover :indeterminate :last :left :maximized :middle :minimized :movable :next-selected :no-frame :non-exclusive :off :on :only-one :open :pressed :previous-selected :read-only :right :selected :top :unchecked :vertical :window QAbstractScrollArea QCheckBox QColumnView QComboBox QDateEdit QDateTimeEdit QDial QDialog QDialogButtonBox QDockWidget QDoubleSpinBox QFrame QGroupBox QHeaderView QLabel QLineEdit QListView QListWidget QMainWindow QMenu QMenuBar QMessageBox QProgressBar QPushButton QRadioButton QScrollBar QSizeGrip QSlider QSpinBox QSplitter QStatusBar QTabBar QTabWidget QTableView QTableWidget QTextEdit QTimeEdit QToolBar QToolBox QToolButton QToolTip QTreeView QTreeWidget QWidget active aliceblue alternate-background-color alternate-base antiquewhite aqua aquamarine azure background background-attachment background-clip background-color background-image background-origin background-position background-repeat backward-icon base beige bisque black blanchedalmond blue blueviolet bold border border-bottom border-bottom-color border-bottom-left-radius border-bottom-right-radius border-bottom-style border-bottom-width border-color border-image border-left border-left-color border-left-style border-left-width border-radius border-right border-right-color border-right-style border-right-width border-style border-top border-top-color border-top-left-radius border-top-right-radius border-top-style border-top-width border-width bottom bright-text brown burlywood button button-layout button-text cadetblue cd-icon center chartreuse chocolate color computer-icon content coral cornflowerblue cornsilk crimson cyan dark darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet dashed deeppink deepskyblue desktop-icon dialog-apply-icon dialog-cancel-icon dialog-close-icon dialog-discard-icon dialog-help-icon dialog-no-icon dialog-ok-icon dialog-open-icon dialog-reset-icon dialog-save-icon dialog-yes-icon dialogbuttonbox-buttons-have-icons dimgray dimgrey directory-closed-icon directory-icon directory-link-icon directory-open-icon disabled dockwidget-close-icon dodgerblue dot-dash dot-dot-dash dotted double downarrow-icon dvd-icon em ex file-icon file-link-icon filedialog-contentsview-icon filedialog-detailedview-icon filedialog-end-icon filedialog-infoview-icon filedialog-listview-icon filedialog-new-directory-icon filedialog-parent-directory-icon filedialog-start-icon firebrick fixed floppy-icon floralwhite font font-family font-size font-style font-weight forestgreen forward-icon fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey gridline-color groove harddisk-icon height highlight highlighted-text home-icon honeydew hotpink hsl hsla hsv hsva icon icon-size image image-position indianred indigo inset italic ivory khaki lavender lavenderblush lawngreen left leftarrow-icon lemonchiffon light lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen lineedit-password-character lineedit-password-mask-delay linen link link-visited magenta margin margin-bottom margin-left margin-right margin-top maroon max-height max-width mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred messagebox-critical-icon messagebox-information-icon messagebox-question-icon messagebox-text-interaction-flags messagebox-warning-icon mid midlight midnightblue min-height min-width mintcream mistyrose moccasin navajowhite navy network-icon no-repeat none normal oblique off oldlace olive olivedrab on opacity orange orangered orchid outline outline-bottom-left-radius outline-bottom-right-radius outline-color outline-offset outline-radius outline-style outline-top-left-radius outline-top-right-radius outset padding padding-bottom padding-left padding-right padding-top paint-alternating-row-colors-for-empty-area palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum position powderblue pt purple px qconicalgradient qlineargradient qradialgradient red repeat repeat-x repeat-y rgb rgba ridge right rightarrow-icon rosybrown royalblue saddlebrown salmon sandybrown scroll seagreen seashell selected selection-background-color selection-color shadow show-decoration-selected sienna silver skyblue slateblue slategray slategrey snow solid spacing springgreen steelblue stretch subcontrol-origin subcontrol-position tan teal text text-align text-decoration thistle titlebar-contexthelp-icon titlebar-maximize-icon titlebar-menu-icon titlebar-minimize-icon titlebar-normal-icon titlebar-shade-icon titlebar-show-tooltips-on-buttons titlebar-unshade-icon tomato top trash-icon turquoise uparrow-icon url violet wheat white whitesmoke widget-animation-duration width window window-text yellow yellowgreen ================================================ FILE: src/qtbox/res/config.json ================================================ { "theme": "white", "mainWindowWidth": 1000, "mainWindowHeight": 600, "codeViewerWidth": 700, "codeViewerHeight": 500, "qssEditorWidth": 850, "qssEditorHeight": 650 } ================================================ FILE: src/qtbox/res/qss/black/editor.qss ================================================ QPlainTextEdit#customEdit { background-color: #2b2b2b; border-top: none; color: white; font-family: "Arial"; } QPushButton#copyBtn { border: none; } QAbstractItemView#completer { background-color: #3b3f42; color: #b2bdaf; font-weight: bold; padding-top: 2px; } QScrollBar#customEditVScrollBar:vertical { width: 2px; background-color: #2b2b2b; } QScrollBar#customEditVScrollBar::handle:vertical { background-color: #b2bdaf; } QScrollBar#customEditHScrollBar:horizontal { height: 2px; background-color: #2b2b2b; } QScrollBar#customEditHScrollBar::handle:horizontal { background-color: #b2bdaf; } QWidget#displayWidget { background-color: #2b2b2b; } QComboBox#widgetComboBox { background-color: #3b3f42; border: 1px solid darkgray; border-radius: 5px; font-weight: bold; color: white; padding-left: 15px; padding-right: 12px; height: 20px; font-family: "Arial"; } QComboBox#widgetComboBox::drop-down { width: 13px; border: none; } QComboBox#widgetComboBox QAbstractItemView { color: white; border: none; outline: none; font-size: 12px; background-color: #2b2b2b; } QComboBox#widgetComboBox QScrollBar:vertical { width: 2px; background-color: white; } QComboBox#widgetComboBox QScrollBar::handle:vertical { background-color: #b2bdaf; } QSplitter#qssEditorBody { border-top: 1px solid #2b2b2b; background-color: #3b3f42; border-right-width: 2px; border-bottom-width: 2px; } QSplitter#qssEditorBody::handle { background-color: #2b2b2b; width: 1px; } ================================================ FILE: src/qtbox/res/qss/black/menu.qss ================================================ QMenu { background-color: #3b3f42; border: 1px solid gray; color: #b2bdaf; border-radius: 3px; } QMenu::icon { padding: 5px 5px 5px 5px; } QMenu::item { padding: 3px 5px 3px 5px; } QMenu::item:selected { background-color: #f1964c; color: black; } ================================================ FILE: src/qtbox/res/qss/black/message_box.qss ================================================ QLabel#titleLabel { color: #d99d3a; font-size: 15px; font-weight: bold; font-family: "Arial"; } QTextBrowser#contentBrowser { background-color: #2b2b2b; color: #b2bdaf; border: none; font-family: "Arial"; } QPushButton#confirmBtn { border: none; background-color: #f1964c; font-size: 13px; color: #f0f0f0; border-radius: 2px; } QPushButton#confirmBtn:hover { background-color: #f0bc5c; } QPushButton#confirmBtn:pressed { background-color: #f1964c; } QPushButton#closeBtn { background-color: #3b3f42; border: none; border-radius: 2px; } QPushButton#closeBtn:hover { background-color: rgba(255, 255, 255, 80); } QPushButton#closeBtn:pressed { background-color: rgba(255, 255, 255, 50); } QScrollBar:vertical { width: 2px; background-color: #2b2b2b; } QScrollBar::handle:vertical { background-color: #b2bdaf; } QScrollBar:horizontal { height: 2px; background-color: #2b2b2b; } QScrollBar::handle:horizontal { background-color: #b2bdaf; } ================================================ FILE: src/qtbox/res/qss/black/title.qss ================================================ QWidget#windowTitle { background-color: #3b3f42; } QPushButton#minimizeBtn, QPushButton#maximizeNormalBtn, QPushButton#closeBtn { background-color: #3b3f42; border-radius: 3px; border: none; } QPushButton#minimizeBtn:hover, QPushButton#maximizeNormalBtn:hover, QPushButton#closeBtn:hover { background-color: rgba(255, 255, 255, 80); } QPushButton#minimizeBtn:pressed, QPushButton#maximizeNormalBtn:pressed, QPushButton#closeBtn:pressed { background-color: rgba(255, 255, 255, 50); } ================================================ FILE: src/qtbox/res/qss/black/viewer.qss ================================================ QTextBrowser#codeViewerBody { background-color: #2b2b2b; border-top: none; border-left: none; border-right-width: 2px; border-bottom-width: 2px; } QPushButton#copyBtn, QPushButton#switchBtn { border: none; } QScrollBar:vertical { width: 2px; background-color: #2b2b2b; } QScrollBar::handle:vertical { background-color: #b2bdaf; } QScrollBar:horizontal { height: 2px; background-color: #2b2b2b; } QScrollBar::handle:horizontal { background-color: #b2bdaf; } ================================================ FILE: src/qtbox/res/qss/black/window_body.qss ================================================ QWidget#windowBody { background-color: #3b3f42; border: none; } QPushButton#listBtn { background-color: #2b2b2b; border: 1px solid gray; font-weight: bold; font-family: "Arial"; font-size: 14px; color: #b2bdaf; } QPushButton#listBtn:hover { background-color: #f1964c; color: black; } QPushButton#listBtn:checked { background-color: #f1964c; color: black; } QPushButton#editorBtn, QPushButton#sponsorBtn, QPushButton#docBtn, QPushButton#aboutBtn, QPushButton#switchBtn { border: none; } QListView#btnList { border: none; background-color: #2b2b2b; } QListView#btnList::item:selected { border: none; } QScrollArea#funcScrollArea, QScrollArea#styleScrollArea { background-color: #2b2b2b; border: 1px solid gray; } QWidget#funcWidget, QWidget#styleWidget { background-color: #2b2b2b; } QTabWidget#tabWidget::tab-bar{ alignment: left; } QTabWidget#tabWidget::pane { border: none; } QTabBar::tab { background-color: #2b2b2b; border: 1px solid gray; border-bottom: none; border-top-left-radius: 4px; border-top-right-radius: 4px; color: #b2bdaf; font-size: 13px; font-weight: bold; font-family: "Arial"; width: 80px; height: 25px; margin-right: 2px; } QTabBar::tab:hover { background-color: #f1964c; color: black; } QTabBar::tab:selected { background-color: #f1964c; color: black; } QScrollBar#btnList:vertical, QScrollBar#funcScrollVBar:vertical, QScrollBar#styleScrollVBar:vertical { width: 2px; background-color: #2b2b2b; } QScrollBar#btnList::handle:vertical, QScrollBar#funcScrollVBar::handle:vertical, QScrollBar#styleScrollVBar::handle:vertical { background-color: #b2bdaf; } QScrollBar#btnList:horizontal, QScrollBar#funcScrollHBar:horizontal, QScrollBar#styleScrollHBar:horizontal { height: 2px; background-color: #2b2b2b; } QScrollBar#btnList::handle:horizontal, QScrollBar#funcScrollHBar::handle:horizontal, QScrollBar#styleScrollHBar::handle:horizontal { background-color: #b2bdaf; } ================================================ FILE: src/qtbox/res/qss/white/editor.qss ================================================ QPlainTextEdit#customEdit { background-color: white; border-top: none; color: black; font-family: "Arial"; } QPushButton#copyBtn { border: none; } QAbstractItemView#completer { background-color: #f2f2f2; color: black; font-weight: bold; padding-top: 2px; } QScrollBar#customEditVScrollBar:vertical { width: 2px; background-color: white; } QScrollBar#customEditVScrollBar::handle:vertical { background-color: #b2bdaf; } QScrollBar#customEditHScrollBar:horizontal { height: 2px; background-color: white; } QScrollBar#customEditHScrollBar::handle:horizontal { background-color: #b2bdaf; } QWidget#displayWidget { background-color: white; } QComboBox#widgetComboBox { background-color: white; border: 1px solid lightgray; border-radius: 5px; font-weight: bold; color: black; height: 20px; padding-left: 15px; padding-right: 12px; font-family: "Arial"; } QComboBox#widgetComboBox::drop-down { width: 13px; border: none; } QComboBox#widgetComboBox QAbstractItemView { color: black; border: none; outline: none; font-size: 12px; background-color: #f2f2f2; } QComboBox#widgetComboBox QScrollBar:vertical { width: 2px; background-color: white; } QComboBox#widgetComboBox QScrollBar::handle:vertical { background-color: #b2bdaf; } QSplitter#qssEditorBody { border-top: 1px solid lightgray; background-color: #f2f2f2; border-right-width: 2px; border-bottom-width: 2px; } QSplitter#qssEditorBody::handle { background-color: #f2f2f2; width: 1px; } ================================================ FILE: src/qtbox/res/qss/white/menu.qss ================================================ QMenu { background-color: #f2f2f2; border: 1px solid whitesmoke; color: black; border-radius: 3px; } QMenu::icon { padding: 5px 5px 5px 5px; } QMenu::item { padding: 3px 5px 3px 5px; } QMenu::item:selected { background-color: #2676bf; color: white; } ================================================ FILE: src/qtbox/res/qss/white/message_box.qss ================================================ QLabel#titleLabel { color: #2676bf; font-size: 15px; font-weight: bold; font-family: "Arial"; } QTextBrowser#contentBrowser { background-color: white; color: black; border: none; font-family: "Arial"; } QPushButton#confirmBtn { border: none; background-color: #2676bf; font-size: 13px; color: #f0f0f0; border-radius: 2px; } QPushButton#confirmBtn:hover { background-color: #3d88cd; } QPushButton#confirmBtn:pressed { background-color: #2676bf; } QPushButton#closeBtn { background-color: #f2f2f2; border: none; border-radius: 2px; } QPushButton#closeBtn:hover { background-color: rgba(255, 255, 255, 150); } QPushButton#closeBtn:pressed { background-color: rgba(255, 255, 255, 120); } QScrollBar:vertical { width: 2px; background-color: white; } QScrollBar::handle:vertical { background-color: #b2bdaf; } QScrollBar:horizontal { height: 2px; background-color: white; } QScrollBar::handle:horizontal { background-color: #b2bdaf; } ================================================ FILE: src/qtbox/res/qss/white/title.qss ================================================ QWidget#windowTitle { background-color: #f2f2f2; } QPushButton#minimizeBtn, QPushButton#maximizeNormalBtn, QPushButton#closeBtn { background-color: #f2f2f2; border-radius: 3px; border: none; } QPushButton#minimizeBtn:hover, QPushButton#maximizeNormalBtn:hover, QPushButton#closeBtn:hover { background-color: rgba(255, 255, 255, 150); } QPushButton#minimizeBtn:pressed, QPushButton#maximizeNormalBtn:pressed, QPushButton#closeBtn:pressed { background-color: rgba(255, 255, 255, 120); } ================================================ FILE: src/qtbox/res/qss/white/viewer.qss ================================================ QTextBrowser#codeViewerBody { background-color: white; border-top: none; border-left: none; border-right-width: 2px; border-bottom-width: 2px; } QPushButton#copyBtn, QPushButton#switchBtn { border: none; } QScrollBar:vertical { width: 2px; background-color: white; } QScrollBar::handle:vertical { background-color: #b2bdaf; } QScrollBar:horizontal { height: 2px; background-color: white; } QScrollBar::handle:horizontal { background-color: #b2bdaf; } ================================================ FILE: src/qtbox/res/qss/white/window_body.qss ================================================ QWidget#windowBody { background-color: #f2f2f2; border: none; } QPushButton#listBtn { background-color: white; border: 1px solid whitesmoke; font-weight: bold; font-family: "Arial"; font-size: 14px; color: black; } QPushButton#listBtn:hover { background-color: #2676bf; color: white; } QPushButton#listBtn:checked { background-color: #2676bf; color: white; } QPushButton#editorBtn, QPushButton#sponsorBtn, QPushButton#docBtn, QPushButton#aboutBtn, QPushButton#switchBtn { border: none; } QListView#btnList { border: none; background-color: white; } QListView#btnList::item:selected { border: none; } QScrollArea#funcScrollArea, QScrollArea#styleScrollArea { background-color: white; border: 1px solid whitesmoke; } QWidget#funcWidget, QWidget#styleWidget { background-color: white; } QTabWidget#tabWidget::tab-bar { alignment: left; } QTabWidget#tabWidget::pane { border: none; } QTabBar::tab { background-color: white; border: 1px solid whitesmoke; border-bottom: none; border-top-left-radius: 4px; border-top-right-radius: 4px; color: black; font-size: 13px; font-weight: bold; font-family: "Arial"; width: 80px; height: 25px; margin-right: 2px; } QTabBar::tab:hover { background-color: #2676bf; color: white; } QTabBar::tab:selected { background-color: #2676bf; color: white; } QScrollBar#btnList:vertical, QScrollBar#funcScrollVBar:vertical, QScrollBar#styleScrollVBar:vertical { width: 2px; background-color: white; } QScrollBar#btnList::handle:vertical, QScrollBar#funcScrollVBar::handle:vertical, QScrollBar#styleScrollVBar::handle:vertical { background-color: #b2bdaf; } QScrollBar#btnList:horizontal, QScrollBar#funcScrollHBar:horizontal, QScrollBar#styleScrollHBar:horizontal { height: 2px; background-color: white; } QScrollBar#btnList::handle:horizontal, QScrollBar#funcScrollHBar::handle:horizontal, QScrollBar#styleScrollHBar::handle:horizontal { background-color: #b2bdaf; } ================================================ FILE: src/qtbox/utils/__init__.py ================================================ ================================================ FILE: src/qtbox/utils/check.py ================================================ from urllib.request import urlopen from threading import Thread import ssl def compare_version(): try: context = ssl._create_unverified_context() r = urlopen("https://la-vie-est-belle.github.io/qtbox/CHANGELOG", context=context, timeout=1) remote_version = r.readline().decode().strip() except Exception as e: return current_version = "v1.2.0" if remote_version != current_version: print(f"Qt Box {remote_version} is available. Upgrade it with command `pip install --upgrade qtbox`") def check_update(): Thread(target=compare_version).start() ================================================ FILE: src/qtbox/utils/output.py ================================================ import os import sys class suppress_stdout_stderr(object): def __enter__(self): self.outnull_file = open(os.devnull, 'w') self.errnull_file = open(os.devnull, 'w') self.old_stdout_fileno_undup = sys.stdout.fileno() self.old_stderr_fileno_undup = sys.stderr.fileno() self.old_stdout_fileno = os.dup(sys.stdout.fileno()) self.old_stderr_fileno = os.dup(sys.stderr.fileno()) self.old_stdout = sys.stdout self.old_stderr = sys.stderr os.dup2(self.outnull_file.fileno(), self.old_stdout_fileno_undup) os.dup2(self.errnull_file.fileno(), self.old_stderr_fileno_undup) sys.stdout = self.outnull_file sys.stderr = self.errnull_file return self def __exit__(self, *_): sys.stdout = self.old_stdout sys.stderr = self.old_stderr os.dup2(self.old_stdout_fileno, self.old_stdout_fileno_undup) os.dup2(self.old_stderr_fileno, self.old_stderr_fileno_undup) os.close(self.old_stdout_fileno) os.close(self.old_stderr_fileno) self.outnull_file.close() self.errnull_file.close()