PyQt custom titlebar setter (movable/resizable, etc.)
Project description
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.
Requirements
- PyQt5 >= 5.15 - This package is using startSystemMove, startSystemResize which were both introduced in Qt 5.15.
Setup
python -m pip install pyqt-custom-titlebar-setter
Included Packages
Usage
-
`CustomTitlebarSetter.getCustomTitleBarWindow(main_window: QWidget, title: str = '', icon_filename: str = '',
font: QFont = QFont('Arial', 12), 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 withsetWindowTitle
. -
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. -
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
1. Very basic text editor
Code Sample
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
How about dark theme?
If you want to set dark theme, install the pyqt-style-setter, then write code like this.
...
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 automatically.
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. pyqt-dark-notepad - DarkNotepadApp
class
Code Sample
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
3. pyqt-dark-calculator - CalculatorApp
class
Code Sample
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
4. pyqt-comic-viewer - ComicBookViewerApp
class
Code Sample
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyqt-custom-titlebar-setter-0.0.12.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50eee3ba3442b21ce7c4aa6e1be6e4ab4b2e114c66253b34ceb4850e972fd26b |
|
MD5 | e8a8802595ed0f9d482cb70420ddc2e3 |
|
BLAKE2b-256 | 6f408f21df02389e88e3099e2d4d4af7463b7ccbb78c0c4788e9b98e26834e00 |
Hashes for pyqt_custom_titlebar_setter-0.0.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a1196f9ea21a12c251a129cb4e8fa850a459cf0c21d55d41d0f96f14a1e924d |
|
MD5 | f7c4aab06c01c0583db547b3dff14658 |
|
BLAKE2b-256 | e2dcb22328737c20f8b63ffbac70b0ba9feef8106b013968565c7fdc4eef8157 |