PyQt custom titlebar window (resizable, movable, minimize/maximize/close, etc.)
Project description
pyqt-custom-titlebar-window
PyQt custom titlebar window(resizable, movable, minimize/maximize/close).
User can set modernized and customized frame surrounding the widget you made.
You can set the title bar separately or set the menu bar as title bar.
Basic buttons like min/max/close are automatically set by user's OS.
You can set your customized buttons(e.g. min/max/close).
You can drag title bar or menu bar on widget to move the window, double-click it to show maximize/normal.
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 9~12 which is not too big, not too small.
If you want to set custom titlebar easily than use pyqt-custom-titlebar-setter.
If you want to use this in various ways than use this directly. see the example below.
Table of Contents
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-window
Included Packages
-
pyqt-frameless-window - To import parent class
FramelessWindow
-
pyqt-windows-buttons-widget - To provide Windows 10 OS style min/max/close buttons with menu bar
-
pyqt-mac-buttons-widget - To provide macOS style of min/max/close buttons with menu bar
-
pyqt-top-titlebar-widget - For adding top title bar feature
-
pyqt-svg-label - For setting icon/title to menu bar if user shows menu bar only
-
absresgetter - For get absoulte resource path of svg icon to set window icon
Feature
-
If you drag the frame, window will be resized.
-
If you drag the title bar(menu bar if there is no title bar) of inner widget, window will be moved.
-
If you double-click the menu bar, window will be maximized/normalized.
-
Set the window title by itself if you set your inner widget's title with
setWindowTitle
. It also catches thewindowTitleChanged
signal of your inner widget. -
Support full screen feature. When full screen feature turns on, top title bar will disappear. Reappear when it turns off.
-
CustomTitlebarWindow(CustomizedWidgetByUser())
- Constructor. -
setTopTitleBar(self, title: str = '', icon_filename: str = '', font: QFont = QFont('Arial', 14), align=Qt.AlignCenter, bottom_separator=False)
to set title bar on the top of the window.font
size should be at least 14. -
setButtons(btnWidget=None, align=Qt.AlignRight)
to add buttons(e.g. min/max/close) on the top right/left corner of title/menu bar. IfbtnWidget
is set to None, buttons' style are automatically set to your platform/OS friendly style. Basically you can givebtnWidget
to your customized buttons(pyqt-titlebar-buttons-widget). I will explain it better. Sorry for weak explanation. -
setButtonHint(hint)
to set hints of buttons. There are three options available(close, min/close, min/max/close). Default value is min/max/close. -
setMenuTitle(self, title: str = '', icon_filename: str = '', font: QFont = QFont('Arial', 9))
to set the icon and title not only on the left side of menu bar, but also set it as window icon and title.font
size should be at least 9.
Note: using this function, macOS
button will be positioned to right which is unorthodox.
-
Frame's color synchronizes with the
QMenuBar
's background color or innerQWidget
's color if inner widget is notQMainWindow
. -
getCornerWidget()
to get corner widget ofQMenuBar
easily -
getInnerWidget()
to get inner widget easily
Example
Code Sample (Menu bar only)
from PyQt5.QtWidgets import QApplication
from pyqt_custom_titlebar_window import CustomTitlebarWindow
from pyqt_dark_calculator import Calculator
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
customTitlebarWindow = CustomTitlebarWindow(Calculator())
customTitlebarWindow.setMenuTitle(icon_filename='calculator.svg')
# customTitlebarWindow.setButtonHint(hint=['close'])
customTitlebarWindow.setButtons()
customTitlebarWindow.show()
app.exec_()
In the code sample, pyqt-dark-calculator is being used as inner widget.
Result
Here's another example with pyqt-dark-notepad.
As you see, existing corner widget doesn't matter.
Code Sample (Including title bar)
from PyQt5.QtWidgets import QApplication
from pyqt_custom_titlebar_window import CustomTitlebarWindow
from pyqt_dark_notepad import DarkNotepad
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
window = DarkNotepad()
customTitlebarWindow = CustomTitlebarWindow(window)
customTitlebarWindow.setTopTitleBar(icon_filename='dark-notepad.svg')
# customTitlebarWindow.setButtonHint(['close'])
customTitlebarWindow.setButtons()
customTitlebarWindow.show()
app.exec_()
Result
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file pyqt-custom-titlebar-window-0.0.32.tar.gz
.
File metadata
- Download URL: pyqt-custom-titlebar-window-0.0.32.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/0.0.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8de1fcb1b6dc3a6b97ec085c6d8a7fe9e13760f71b20dc6d371556f47bba9e8 |
|
MD5 | cad92b1113b1bb5a9fcb1f57d976547c |
|
BLAKE2b-256 | 0e9477b726071ec42cd521b5a48bfa92524a42494e312772493b74fa86d4a9fa |
File details
Details for the file pyqt_custom_titlebar_window-0.0.32-py3-none-any.whl
.
File metadata
- Download URL: pyqt_custom_titlebar_window-0.0.32-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/0.0.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5ba46beb8a4818407eb2481e18ad1c9682de4fc330d088017c6330990a29073 |
|
MD5 | 0f9bc6e9e99990f7bcdb535966bab161 |
|
BLAKE2b-256 | fa6ac16f7a272daa54258c6379d2097cc4d390f5bfb5136d07491f0859784888 |