pyqt-custom-titlebar-setter


Namepyqt-custom-titlebar-setter JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/yjg30737/pyqt-custom-titlebar-setter.git
SummaryPyQt custom titlebar setter (movable/resizable, etc.)
upload_time2024-09-05 13:29:09
maintainerNone
docs_urlNone
authorJung Gyu Yoon
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# pyqt-custom-titlebar-setter

PyQt custom titlebar setter.



This is movable/resizable. 



When resizing, cursor shape will be automatically changed depends on the direction of edge where the cursor is hovering over.



For example, you want to resize the window horizontally, cursor shape will be changed like "⇿".



You can set the title, and icon which should be SVG type.



You can set the min/max/close buttons separately.



This package supports full-screen. If your app has full screen, this custom titlebar can perfectly deal with it. So there's no need to do another chore for full-screen.



This also makes the application's font look better by setting the font family to 'Arial'(which looks modern and commonly used), antialiasing.



The range of font size is set to 12~30 which is not too big, not too small.



## Requirements

* PyQt5 >= 5.15 - This package is using <a href="https://doc.qt.io/qt-5/qwindow.html#startSystemMove">startSystemMove</a>, <a href="https://doc.qt.io/qt-5/qwindow.html#startSystemResize">startSystemResize</a> which were both introduced in Qt 5.15.



## Setup

`python -m pip install pyqt-custom-titlebar-setter`



## Included Packages

* <a href="https://github.com/yjg30737/pyqt-custom-titlebar-window.git">pyqt-custom-titlebar-window</a>



## Usage



```python

CustomTitlebarSetter.getCustomTitleBarWindow(main_window: QWidget, 

                                             title: str = '', 

                                             icon_filename: str = '',

                                             font: QFont = QFont('Arial', 14), 

                                             hint: list = ['min', 'max', 'close'],

                                             align=Qt.AlignCenter, 

                                             bottom_separator: bool = False

                                             ) -> CustomTitlebarWindow

```

* `main_window` is your widget.

* `title` is windows title. If you set this by default (empty string), title is based of the title you set with <a href="https://doc.qt.io/qt-5/qwidget.html#windowTitle-prop">`setWindowTitle`</a>.

* `icon_filename` is title bar's icon. Icon file should be svg file. If it is not set, then there is no icon.

* `font` is font of the title. Font size should be at least 14. 

* `hint` is hint of the button on the title bar. For example, if you give the value such as ['min', 'close'], the title bar buttons will contain minimize and close buttons only.

* `align` is alignment of the title. You can give Qt.AlignLeft, Qt.AlignCenter, Qt.AlignRight. Some of these are not recommended depending on the title bar button's position.

* `bottom_separator` decides whether you want to put the separator(horizontal line) at the bottom of the title bar. If it is set to True, line will be shown between title bar and main widget.



## Example

### 0. Simple way for people who clone this package



`test.py` is included in package just for people who cloned this for testing.



`python test.py`



### 1. Very basic text editor

Code Sample



```python

from PyQt5.QtWidgets import QApplication, QWidget, QGridLayout, QTextEdit

from pyqt_custom_titlebar_setter import CustomTitlebarSetter





class TextEditor(QWidget):

    def __init__(self):

        super().__init__()

        self.__initUi()



    def __initUi(self):

        self.setWindowTitle('Text Editor')

        lay = QGridLayout()

        lay.addWidget(QTextEdit())

        self.setLayout(lay)





if __name__ == "__main__":

    import sys



    app = QApplication(sys.argv)

    widget = TextEditor()

    window = CustomTitlebarSetter.getCustomTitleBarWindow(main_window=widget, icon_filename='dark-notepad.svg')

    window.show()

    sys.exit(app.exec_())

```



Result



![image](https://user-images.githubusercontent.com/55078043/167746119-c3715693-d7f9-4cb5-8c1c-76b3de372c3c.png)



How about dark theme?



![image](https://user-images.githubusercontent.com/55078043/167748426-adcc8b70-2778-4ccb-9fcf-26448a254e9f.png)



If you want to set dark theme, install the <a href="https://github.com/yjg30737/pyqt-style-setter.git">pyqt-style-setter</a>, then write code like this.



```python

...

widget = TextEditor()

StyleSetter.setWindowStyle(widget, theme='dark') # write it at this spot, BEFORE calling getCustomTitleBarWindow.

window = CustomTitlebarSetter.getCustomTitleBarWindow(main_window=widget, icon_filename='dark-notepad.svg')

...

```



By the way, you can clearly see the title label and min/max/close button color changed based on background's color <b>automatically</b>.





Now let's apply this to some of the applications.



※ From now on, examples below are using dark theme. Of course, you don't have to use this.

### 2. <a href="https://github.com/yjg30737/pyqt-dark-notepad.git">pyqt-dark-notepad</a> - `DarkNotepadApp` class

Code Sample



```python

from PyQt5.QtWidgets import QApplication

from pyqt_dark_gray_theme.darkGrayTheme import *

from pyqt_dark_notepad import DarkNotepad



from pyqt_style_setter import StyleSetter

from pyqt_custom_titlebar_setter import CustomTitlebarSetter





class DarkNotepadApp(QApplication):

    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        mainWindow = DarkNotepad()

        StyleSetter.setWindowStyle(mainWindow, theme='dark')  # you don't need this. this is just for adding style.

        self.__titleBarWindow = CustomTitlebarSetter.getCustomTitleBarWindow(mainWindow,

                                                                             icon_filename='ico/dark-notepad.svg')

        self.__titleBarWindow.show()

```



Result



![image](https://user-images.githubusercontent.com/55078043/172275943-d69d9427-8972-47a2-a4db-54d3e884d105.png)



### 3. <a href="https://github.com/yjg30737/pyqt-dark-calculator.git">pyqt-dark-calculator</a> - `CalculatorApp` class

Code Sample



```python

from PyQt5.QtWidgets import QApplication, QAbstractButton

from pyqt_dark_gray_theme.darkGrayTheme import *

from pyqt_dark_calculator.calculator import Calculator



from pyqt_style_setter import StyleSetter

from pyqt_custom_titlebar_setter import CustomTitlebarSetter





class CalculatorApp(QApplication):

    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        mainWindow = Calculator()

        StyleSetter.setWindowStyle(mainWindow, theme='dark', exclude_type_lst=[QAbstractButton])

        self.__titleBarWindow = CustomTitlebarSetter.getCustomTitleBarWindow(mainWindow,

                                                                             icon_filename='ico/calculator.svg')

        self.__titleBarWindow.show()

```



Result



![image](https://user-images.githubusercontent.com/55078043/172276222-6c5ffac6-da6c-4946-97a9-12cc0f1bf058.png)



### 4. <a href="https://github.com/yjg30737/pyqt-comic-viewer.git">pyqt-comic-viewer</a> - `ComicBookViewerApp` class

Code Sample



```python

from PyQt5.QtWidgets import QApplication

from pyqt_dark_gray_theme.darkGrayTheme import *

from pyqt_comic_viewer.comicBookViewer import ComicBookViewer



from pyqt_style_setter import StyleSetter

from pyqt_custom_titlebar_setter import CustomTitlebarSetter





class ComicBookViewerApp(QApplication):

    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        mainWindow = ComicBookViewer()

        StyleSetter.setWindowStyle(mainWindow, theme='dark')

        self.__titleBarWindow = CustomTitlebarSetter.getCustomTitleBarWindow(mainWindow, icon_filename='ico/book.svg')

        self.__titleBarWindow.show()

```



Result



![image](https://user-images.githubusercontent.com/55078043/172276340-f390dc34-6bdf-4547-a70e-fca161d11e83.png)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/yjg30737/pyqt-custom-titlebar-setter.git",
    "name": "pyqt-custom-titlebar-setter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Jung Gyu Yoon",
    "author_email": "yjg30737@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/77/a3/425ad329be27508fa60a4393f0a07a1a6a2416ff043314932b0d45d42c7c/pyqt_custom_titlebar_setter-0.1.0.tar.gz",
    "platform": null,
    "description": "\r\n# pyqt-custom-titlebar-setter\r\n\r\nPyQt custom titlebar setter.\r\n\r\n\r\n\r\nThis is movable/resizable. \r\n\r\n\r\n\r\nWhen resizing, cursor shape will be automatically changed depends on the direction of edge where the cursor is hovering over.\r\n\r\n\r\n\r\nFor example, you want to resize the window horizontally, cursor shape will be changed like \"\u21ff\".\r\n\r\n\r\n\r\nYou can set the title, and icon which should be SVG type.\r\n\r\n\r\n\r\nYou can set the min/max/close buttons separately.\r\n\r\n\r\n\r\nThis package supports full-screen. If your app has full screen, this custom titlebar can perfectly deal with it. So there's no need to do another chore for full-screen.\r\n\r\n\r\n\r\nThis also makes the application's font look better by setting the font family to 'Arial'(which looks modern and commonly used), antialiasing.\r\n\r\n\r\n\r\nThe range of font size is set to 12~30 which is not too big, not too small.\r\n\r\n\r\n\r\n## Requirements\r\n\r\n* PyQt5 >= 5.15 - This package is using <a href=\"https://doc.qt.io/qt-5/qwindow.html#startSystemMove\">startSystemMove</a>, <a href=\"https://doc.qt.io/qt-5/qwindow.html#startSystemResize\">startSystemResize</a> which were both introduced in Qt 5.15.\r\n\r\n\r\n\r\n## Setup\r\n\r\n`python -m pip install pyqt-custom-titlebar-setter`\r\n\r\n\r\n\r\n## Included Packages\r\n\r\n* <a href=\"https://github.com/yjg30737/pyqt-custom-titlebar-window.git\">pyqt-custom-titlebar-window</a>\r\n\r\n\r\n\r\n## Usage\r\n\r\n\r\n\r\n```python\r\n\r\nCustomTitlebarSetter.getCustomTitleBarWindow(main_window: QWidget, \r\n\r\n                                             title: str = '', \r\n\r\n                                             icon_filename: str = '',\r\n\r\n                                             font: QFont = QFont('Arial', 14), \r\n\r\n                                             hint: list = ['min', 'max', 'close'],\r\n\r\n                                             align=Qt.AlignCenter, \r\n\r\n                                             bottom_separator: bool = False\r\n\r\n                                             ) -> CustomTitlebarWindow\r\n\r\n```\r\n\r\n* `main_window` is your widget.\r\n\r\n* `title` is windows title. If you set this by default (empty string), title is based of the title you set with <a href=\"https://doc.qt.io/qt-5/qwidget.html#windowTitle-prop\">`setWindowTitle`</a>.\r\n\r\n* `icon_filename` is title bar's icon. Icon file should be svg file. If it is not set, then there is no icon.\r\n\r\n* `font` is font of the title. Font size should be at least 14. \r\n\r\n* `hint` is hint of the button on the title bar. For example, if you give the value such as ['min', 'close'], the title bar buttons will contain minimize and close buttons only.\r\n\r\n* `align` is alignment of the title. You can give Qt.AlignLeft, Qt.AlignCenter, Qt.AlignRight. Some of these are not recommended depending on the title bar button's position.\r\n\r\n* `bottom_separator` decides whether you want to put the separator(horizontal line) at the bottom of the title bar. If it is set to True, line will be shown between title bar and main widget.\r\n\r\n\r\n\r\n## Example\r\n\r\n### 0. Simple way for people who clone this package\r\n\r\n\r\n\r\n`test.py` is included in package just for people who cloned this for testing.\r\n\r\n\r\n\r\n`python test.py`\r\n\r\n\r\n\r\n### 1. Very basic text editor\r\n\r\nCode Sample\r\n\r\n\r\n\r\n```python\r\n\r\nfrom PyQt5.QtWidgets import QApplication, QWidget, QGridLayout, QTextEdit\r\n\r\nfrom pyqt_custom_titlebar_setter import CustomTitlebarSetter\r\n\r\n\r\n\r\n\r\n\r\nclass TextEditor(QWidget):\r\n\r\n    def __init__(self):\r\n\r\n        super().__init__()\r\n\r\n        self.__initUi()\r\n\r\n\r\n\r\n    def __initUi(self):\r\n\r\n        self.setWindowTitle('Text Editor')\r\n\r\n        lay = QGridLayout()\r\n\r\n        lay.addWidget(QTextEdit())\r\n\r\n        self.setLayout(lay)\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\r\n    import sys\r\n\r\n\r\n\r\n    app = QApplication(sys.argv)\r\n\r\n    widget = TextEditor()\r\n\r\n    window = CustomTitlebarSetter.getCustomTitleBarWindow(main_window=widget, icon_filename='dark-notepad.svg')\r\n\r\n    window.show()\r\n\r\n    sys.exit(app.exec_())\r\n\r\n```\r\n\r\n\r\n\r\nResult\r\n\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/55078043/167746119-c3715693-d7f9-4cb5-8c1c-76b3de372c3c.png)\r\n\r\n\r\n\r\nHow about dark theme?\r\n\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/55078043/167748426-adcc8b70-2778-4ccb-9fcf-26448a254e9f.png)\r\n\r\n\r\n\r\nIf you want to set dark theme, install the <a href=\"https://github.com/yjg30737/pyqt-style-setter.git\">pyqt-style-setter</a>, then write code like this.\r\n\r\n\r\n\r\n```python\r\n\r\n...\r\n\r\nwidget = TextEditor()\r\n\r\nStyleSetter.setWindowStyle(widget, theme='dark') # write it at this spot, BEFORE calling getCustomTitleBarWindow.\r\n\r\nwindow = CustomTitlebarSetter.getCustomTitleBarWindow(main_window=widget, icon_filename='dark-notepad.svg')\r\n\r\n...\r\n\r\n```\r\n\r\n\r\n\r\nBy the way, you can clearly see the title label and min/max/close button color changed based on background's color <b>automatically</b>.\r\n\r\n\r\n\r\n\r\n\r\nNow let's apply this to some of the applications.\r\n\r\n\r\n\r\n\u203b From now on, examples below are using dark theme. Of course, you don't have to use this.\r\n\r\n### 2. <a href=\"https://github.com/yjg30737/pyqt-dark-notepad.git\">pyqt-dark-notepad</a> - `DarkNotepadApp` class\r\n\r\nCode Sample\r\n\r\n\r\n\r\n```python\r\n\r\nfrom PyQt5.QtWidgets import QApplication\r\n\r\nfrom pyqt_dark_gray_theme.darkGrayTheme import *\r\n\r\nfrom pyqt_dark_notepad import DarkNotepad\r\n\r\n\r\n\r\nfrom pyqt_style_setter import StyleSetter\r\n\r\nfrom pyqt_custom_titlebar_setter import CustomTitlebarSetter\r\n\r\n\r\n\r\n\r\n\r\nclass DarkNotepadApp(QApplication):\r\n\r\n    def __init__(self, *args, **kwargs):\r\n\r\n        super().__init__(*args, **kwargs)\r\n\r\n        mainWindow = DarkNotepad()\r\n\r\n        StyleSetter.setWindowStyle(mainWindow, theme='dark')  # you don't need this. this is just for adding style.\r\n\r\n        self.__titleBarWindow = CustomTitlebarSetter.getCustomTitleBarWindow(mainWindow,\r\n\r\n                                                                             icon_filename='ico/dark-notepad.svg')\r\n\r\n        self.__titleBarWindow.show()\r\n\r\n```\r\n\r\n\r\n\r\nResult\r\n\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/55078043/172275943-d69d9427-8972-47a2-a4db-54d3e884d105.png)\r\n\r\n\r\n\r\n### 3. <a href=\"https://github.com/yjg30737/pyqt-dark-calculator.git\">pyqt-dark-calculator</a> - `CalculatorApp` class\r\n\r\nCode Sample\r\n\r\n\r\n\r\n```python\r\n\r\nfrom PyQt5.QtWidgets import QApplication, QAbstractButton\r\n\r\nfrom pyqt_dark_gray_theme.darkGrayTheme import *\r\n\r\nfrom pyqt_dark_calculator.calculator import Calculator\r\n\r\n\r\n\r\nfrom pyqt_style_setter import StyleSetter\r\n\r\nfrom pyqt_custom_titlebar_setter import CustomTitlebarSetter\r\n\r\n\r\n\r\n\r\n\r\nclass CalculatorApp(QApplication):\r\n\r\n    def __init__(self, *args, **kwargs):\r\n\r\n        super().__init__(*args, **kwargs)\r\n\r\n        mainWindow = Calculator()\r\n\r\n        StyleSetter.setWindowStyle(mainWindow, theme='dark', exclude_type_lst=[QAbstractButton])\r\n\r\n        self.__titleBarWindow = CustomTitlebarSetter.getCustomTitleBarWindow(mainWindow,\r\n\r\n                                                                             icon_filename='ico/calculator.svg')\r\n\r\n        self.__titleBarWindow.show()\r\n\r\n```\r\n\r\n\r\n\r\nResult\r\n\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/55078043/172276222-6c5ffac6-da6c-4946-97a9-12cc0f1bf058.png)\r\n\r\n\r\n\r\n### 4. <a href=\"https://github.com/yjg30737/pyqt-comic-viewer.git\">pyqt-comic-viewer</a> - `ComicBookViewerApp` class\r\n\r\nCode Sample\r\n\r\n\r\n\r\n```python\r\n\r\nfrom PyQt5.QtWidgets import QApplication\r\n\r\nfrom pyqt_dark_gray_theme.darkGrayTheme import *\r\n\r\nfrom pyqt_comic_viewer.comicBookViewer import ComicBookViewer\r\n\r\n\r\n\r\nfrom pyqt_style_setter import StyleSetter\r\n\r\nfrom pyqt_custom_titlebar_setter import CustomTitlebarSetter\r\n\r\n\r\n\r\n\r\n\r\nclass ComicBookViewerApp(QApplication):\r\n\r\n    def __init__(self, *args, **kwargs):\r\n\r\n        super().__init__(*args, **kwargs)\r\n\r\n        mainWindow = ComicBookViewer()\r\n\r\n        StyleSetter.setWindowStyle(mainWindow, theme='dark')\r\n\r\n        self.__titleBarWindow = CustomTitlebarSetter.getCustomTitleBarWindow(mainWindow, icon_filename='ico/book.svg')\r\n\r\n        self.__titleBarWindow.show()\r\n\r\n```\r\n\r\n\r\n\r\nResult\r\n\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/55078043/172276340-f390dc34-6bdf-4547-a70e-fca161d11e83.png)\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "PyQt custom titlebar setter (movable/resizable, etc.)",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/yjg30737/pyqt-custom-titlebar-setter.git"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79e42cb777ec5bd98cd8d6494690f92618e367309d4a93d8c947707329fdd93c",
                "md5": "0ebc8f2020be0c33d5800b613edeb8b3",
                "sha256": "275a310d517c18428b1f5e7d8b8b5734bcd21524e8c8a1d23fafb5691f4314f4"
            },
            "downloads": -1,
            "filename": "pyqt_custom_titlebar_setter-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0ebc8f2020be0c33d5800b613edeb8b3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5362,
            "upload_time": "2024-09-05T13:29:07",
            "upload_time_iso_8601": "2024-09-05T13:29:07.949571Z",
            "url": "https://files.pythonhosted.org/packages/79/e4/2cb777ec5bd98cd8d6494690f92618e367309d4a93d8c947707329fdd93c/pyqt_custom_titlebar_setter-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "77a3425ad329be27508fa60a4393f0a07a1a6a2416ff043314932b0d45d42c7c",
                "md5": "b2e116c5dbd69601fc44adb6b1b29339",
                "sha256": "d854c8101bbe23a64775bd11405d18847bd0e2a9de60948550156aeb780a65bc"
            },
            "downloads": -1,
            "filename": "pyqt_custom_titlebar_setter-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b2e116c5dbd69601fc44adb6b1b29339",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5118,
            "upload_time": "2024-09-05T13:29:09",
            "upload_time_iso_8601": "2024-09-05T13:29:09.331615Z",
            "url": "https://files.pythonhosted.org/packages/77/a3/425ad329be27508fa60a4393f0a07a1a6a2416ff043314932b0d45d42c7c/pyqt_custom_titlebar_setter-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-05 13:29:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yjg30737",
    "github_project": "pyqt-custom-titlebar-setter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "pyqt-custom-titlebar-setter"
}
        
Elapsed time: 0.27602s