Skip to content

Commit

Permalink
添加标题栏基类 TitleBarBase
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyiYo committed Aug 7, 2023
1 parent b43ae7f commit f1b1ac3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions qframelesswindow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
:license: GPLv3, see LICENSE for more details.
"""

__version__ = "0.2.9"
__version__ = "0.3.0"

import sys

from PyQt5.QtWidgets import QDialog, QMainWindow

from .titlebar import TitleBar, TitleBarButton, SvgTitleBarButton, StandardTitleBar
from .titlebar import TitleBar, TitleBarButton, SvgTitleBarButton, StandardTitleBar, TitleBarBase

if sys.platform == "win32":
from .windows import AcrylicWindow
Expand Down
33 changes: 21 additions & 12 deletions qframelesswindow/titlebar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,20 @@
SvgTitleBarButton, TitleBarButton)


class TitleBar(QWidget):
""" Title bar with minimize, maximum and close button """
class TitleBarBase(QWidget):
""" Title bar base class """

def __init__(self, parent):
super().__init__(parent)
self.minBtn = MinimizeButton(parent=self)
self.closeBtn = CloseButton(parent=self)
self.maxBtn = MaximizeButton(parent=self)
self.hBoxLayout = QHBoxLayout(self)

self._isDoubleClickEnabled = True

self.resize(200, 32)
self.setFixedHeight(32)

# add buttons to layout
self.hBoxLayout.setSpacing(0)
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.hBoxLayout.setAlignment(Qt.AlignVCenter | Qt.AlignLeft)
self.hBoxLayout.addStretch(1)
self.hBoxLayout.addWidget(self.minBtn, 0, Qt.AlignRight)
self.hBoxLayout.addWidget(self.maxBtn, 0, Qt.AlignRight)
self.hBoxLayout.addWidget(self.closeBtn, 0, Qt.AlignRight)

# connect signal to slot
self.minBtn.clicked.connect(self.window().showMinimized)
self.maxBtn.clicked.connect(self.__toggleMaxState)
Expand Down Expand Up @@ -102,6 +93,24 @@ def setDoubleClickEnabled(self, isEnabled):
self._isDoubleClickEnabled = isEnabled



class TitleBar(TitleBarBase):
""" Title bar with minimize, maximum and close button """

def __init__(self, parent):
super().__init__(parent)
self.hBoxLayout = QHBoxLayout(self)

# add buttons to layout
self.hBoxLayout.setSpacing(0)
self.hBoxLayout.setContentsMargins(0, 0, 0, 0)
self.hBoxLayout.setAlignment(Qt.AlignVCenter | Qt.AlignLeft)
self.hBoxLayout.addStretch(1)
self.hBoxLayout.addWidget(self.minBtn, 0, Qt.AlignRight)
self.hBoxLayout.addWidget(self.maxBtn, 0, Qt.AlignRight)
self.hBoxLayout.addWidget(self.closeBtn, 0, Qt.AlignRight)


class StandardTitleBar(TitleBar):
""" Title bar with icon and title """

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name="PyQt5-Frameless-Window",
version="0.2.9",
version="0.3.0",
keywords="pyqt frameless",
author="zhiyiYo",
author_email="shokokawaii@outlook.com",
Expand Down

0 comments on commit f1b1ac3

Please sign in to comment.