Giter Site home page Giter Site logo

yjg30737 / pyqt-frameless-window Goto Github PK

View Code? Open in Web Editor NEW
38.0 2.0 5.0 213 KB

PyQt(+PySide) Frameless Window

License: MIT License

Python 100.00%
pyqt5-frameless-window pyqt5 pyqt qt pyqt5-examples qcursor qwidget qwindow framelesswindow pyqt5-tutorial

pyqt-frameless-window's Introduction

pyqt-frameless-window

PyQt(+PySide) Frameless Window

Feature

  • Frameless
  • Using Windows API (for Windows OS effect - shadow, rounded, animation, etc.)
  • Supports PyQt5, PySide2, PySide6
  • User can make it enable/disable to move, resize
  • Supports QWidget, QDialog, QMainWindow
  • Support title bar. You can decide either show or hide it.

Note

I strongly recommend legacy version if your OS is not Windows and that's saying a lot.

If you want to enhance this project, feel free to contribute macOS and Linux feature, since i don't afford to do test of pyqt-frameless-window in those OS.

Requirements

  • qtpy - To use PyQt5, PySide2(Qt version 5), PySide6(Qt version 6)
  • pywin32 - For using Windows API feature

Setup

New version (using Windows API)

clone

  1. git clone ~
  2. pip install -r requirements.txt

You can skip below, it's just for testing.

  1. python sample_dialog_pyside6.py (Frameless dialog with PySide6)
  2. python sample_mainwindow_pyqt5.py (Frameless main window with PyQt5)
  3. python sample_widget_pyside6.py (Frameless widget with PySide6)

pip

python -m pip install pyqt-frameless-window

Legacy version

python -m pip install pyqt-frameless-window==0.0.61

Class Overview

Recommend to use FramelessWidget, the others have multiple inheritance, so it can cause unexpected problem (haven't found any so far, though)

  • FramelessWidget(hint=None) - frameless QWidget
  • FramelessDialog(hint=None) - frameless QDialog
  • FramelessMainWindow(hint=None) - frameless QMainWindow

About hint

You can give the list of buttons on the right top of the menu bar with hint like ['full_screen', 'min', 'max', 'close'].

['min', 'max', 'close'] will set by default if you don't give any arguments.

Available arguments (since v0.0.78)

  • full_screen (still buggy, for example you can resize the full-screen window if you put the cusror to the very edge of the window)
  • min
  • max
  • close

You can set the list of them with setTitleBarHint(hint: list) as well. (since v0.0.82)

Method Overview

== FramelessWidget, FramelessDialog, FramelessMainWindow ==

For Windows & The Others

  • setResizable(f: bool) - Set resizable/none-resizable.
  • isResizable() -> bool - Check if window is resizable or not
  • setPressToMove(f: bool) - Set movable/non-movable
  • isPressToMove() -> bool - Check if window is movable or not
  • New Version Only
    • setWindowIcon(filename: str) - Set the icon to the title bar. This method is overriden.
    • setWindowTitle(title: str) - Set the title to the title bar. This method is overriden.
    • setFixedSize(width, height) - Set the fixed width and height. This method is overriden to call setResizable(false).
    • setTitleBarVisible(f: bool) - Set the title bar's visibility. If window is movable, window moving policy will also be decided by this.
      • If you set this true and window is movable, you should click and drag only the title bar to move the window.
      • If you set this false and window is movable, you can click and drag the part of the window which is not occupied by widget to move the window.
    • getTitleBar() - Get the title bar.
    • setTitleBarHint(hint: list) - Set the standard buttons(min, max, close...) of corner widget.

The Others

  • setMargin(margin: int) - Set the margin which allows cursor to change its shape to resize form
  • setFrameColor(color) - Set the background color. color argument type can be both QColor and str.
  • getFrameColor -> QColor - Get the background color.
  • setVerticalExpandedEnabled(f: bool) - Make it able to expand vertically when double-clicking the top or bottom edges of the window.

== TitleBar (New Version Only) ==

  • getIcon() -> QLabel - Get the icon.
  • getTitle() -> QLabel - Get the title.
  • setTitleBarFont(font: QFont) - Set the font of the title bar.
  • setIconSize(w, h) - Set the size of icon on the title bar.

Note: Do not use any functions other than the above.

Preview

Title bar

image

No title bar

If you make the title bar not visible with setTitleBarVisible(False)

image

Try to move and resize it.

Note: Result image was tested in Windows 11, PySide6.

See Also

Legacy version(0.0.61) README - not using Windows API, qtpy, just good old PyQt5. Enable to resize and move as always. (clunky in Windows though) Only for PyQt5 by the way.

TODO list

pyqt-frameless-window's People

Contributors

polsulpicien avatar yjg30737 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyqt-frameless-window's Issues

Transparent window maximized

Hello,

creating a transparent background window (setStyleSheet("background: transparent")) works fine but when you try to maximize this window (setWindowState(Qt.WindowMaximized)) the window isn't transparent anymore.
You don't get this issue when using QMainWindow.
Currently you can have a maximized window using setGeometry(screen.x(), screen.y(), screen.width(), screen.height()), but it would be nice to have the maximized function :D

Note: I'm using the latest version (commit #3228fc1)

Have a nice day,
Thanks ๐Ÿ‘๐Ÿผ

Has the setTitleBarHint() been implemented ?

Hi, as the title says, has Has the setTitleBarHint() been implemented ?

I am trying to show only maximize button in window/dialog, but for some reason, it is not working.

I have tried setting titlebar hints with

titleBar.setTitleBarHint(['max'])

But all three buttons still show.

error ModuleNotFoundError: No module named 'winreg'

i get error when install
python3 -m pip install pyqt-frameless-window

ModuleNotFoundError: No module named 'winreg'

root@minto-Lenovo-V145-14AST:/home/minto/belajar/pysidepro/pyqt-frameless-window# python3 sample.py
Traceback (most recent call last):
File "/home/minto/belajar/pysidepro/pyqt-frameless-window/sample.py", line 8, in
from pyqt_frameless_window import FramelessDialog, FramelessWidget, FramelessMainWindow
File "/home/minto/belajar/pysidepro/pyqt-frameless-window/pyqt_frameless_window/init.py", line 1, in
from pyqt_frameless_window.framelessWindow import FramelessWidget, FramelessDialog, FramelessMainWindow
File "/home/minto/belajar/pysidepro/pyqt-frameless-window/pyqt_frameless_window/framelessWindow.py", line 6, in
from pyqt_frameless_window.base.baseWidget import BaseWidget
File "/home/minto/belajar/pysidepro/pyqt-frameless-window/pyqt_frameless_window/base/baseWidget.py", line 5, in
from pyqt_frameless_window.windows import TitleBar
File "/home/minto/belajar/pysidepro/pyqt-frameless-window/pyqt_frameless_window/windows/init.py", line 1, in
from pyqt_frameless_window.windows.baseWidget import BaseWidget
File "/home/minto/belajar/pysidepro/pyqt-frameless-window/pyqt_frameless_window/windows/baseWidget.py", line 2, in
from winreg import ConnectRegistry, HKEY_CURRENT_USER, OpenKey, KEY_READ, QueryValueEx
ModuleNotFoundError: No module named 'winreg'

QWebEngineView view breaks most of the window functionality

When adding QWebEngineView to the central widget layout the resize and snap functionality stops working.
I'm using windows if that helps.
Minimal code to reproduce:

class MainWindow(QMainWindow, BaseWidget):

    def __init__(self, hint=None):
        super().__init__()
        self._initVal()
        self._initUi(hint)

    def _initUi(self, hint):
        super()._initUi(hint)
        lay = QVBoxLayout()
        lay.addWidget(self._titleBar)
        lay.setContentsMargins(0, 0, 0, 0)
        lay.setSpacing(0)

        lay.addWidget(QWebEngineView())

        mainWidget = QWidget()
        mainWidget.setLayout(lay)

        self.setCentralWidget(mainWidget)

'MainWindow' does not have a signal with the signature changedToDark(bool)

I got a message from terminal, which is ''MainWindow' does not have a signal with the signature changedToDark(bool)' and i haven't found any information about these error message. If i am not mistaken, it is related to your module. Please, can you help me with that situiation?(at least, can you say me where i can find the info about it)

win32utils.py explicitly used `PyQt5` that potentially breaks `PySide6` compatibility

Hi, my project uses PySide6 and running the sample code results in the following error.

Traceback (most recent call last):
  File "C:\Users\wuyua\Documents\Project\CrystalVisionLtd\Embedded\unilab\unilab-panel\app\mainwindow.py", line 9, in <module>
    from pyqt_frameless_window import FramelessDialog, FramelessWidget, FramelessMainWindow
  File "C:\Users\wuyua\AppData\Local\pypoetry\Cache\virtualenvs\unilab-panel-P-d2hT76-py3.10\lib\site-packages\pyqt_frameless_window\__init__.py", line 1, in <module>
    from pyqt_frameless_window.framelessWindow import FramelessWidget, FramelessDialog, FramelessMainWindow
  File "C:\Users\wuyua\AppData\Local\pypoetry\Cache\virtualenvs\unilab-panel-P-d2hT76-py3.10\lib\site-packages\pyqt_frameless_window\framelessWindow.py", line 4, in <module>
    from pyqt_frameless_window.windows.baseWidget import BaseWidget
  File "C:\Users\wuyua\AppData\Local\pypoetry\Cache\virtualenvs\unilab-panel-P-d2hT76-py3.10\lib\site-packages\pyqt_frameless_window\windows\__init__.py", line 1, in <module>
    from pyqt_frameless_window.windows.baseWidget import BaseWidget
  File "C:\Users\wuyua\AppData\Local\pypoetry\Cache\virtualenvs\unilab-panel-P-d2hT76-py3.10\lib\site-packages\pyqt_frameless_window\windows\baseWidget.py", line 13, in <module>
    from pyqt_frameless_window.windows.src import win32utils
  File "C:\Users\wuyua\AppData\Local\pypoetry\Cache\virtualenvs\unilab-panel-P-d2hT76-py3.10\lib\site-packages\pyqt_frameless_window\windows\src\win32utils.py", line 11, in <module>
    from PyQt5.QtWinExtras import QtWin
ModuleNotFoundError: No module named 'PyQt5.QtWinExtras'

Process finished with exit code 1

I found that the win32utils.py imports PyQt5 explicitly. How would it work if my project does not use PyQt5?

Version 0.0.84 missing move event for Windows

In BaseWidget for windows(dont know about others) using 0.0.80 in init there is defined self._pressToMove = True ... but in newer version 0.0.84 there is not defined self._pressToMove = True .. its moved into some _initSomething function .. that is not called .. that variable is not defined .. so there is no way to move window .. error only shows when closing app .. so I had to switch back to older version where it is defined

changing cursor shape on edge hover needs to be more forgiving

extremely cool and sophisticated program. only requires one thing to be perfect, it just needs improvement on the edge detection for the cursor. since it requires too much precision from the user in order to drag the edge when attempting to resize. i'm interested to know on how that maybe done. it would be a great help. looking into ways on how to do that as well. hope it helps

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.