Skip to content

Commit

Permalink
Fix methods for setting widget heights and update default heights (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
haiiliin authored Aug 7, 2024
1 parent 8a889da commit 9afaa74
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
20 changes: 18 additions & 2 deletions pyqtribbon/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class RibbonPanel(QtWidgets.QFrame):
_widgets: List[QtWidgets.QWidget] = []

# height of the title widget
_titleHeight: int = 20
_titleHeight: int = 15

# Panel options signal
panelOptionClicked = QtCore.Signal(bool)
Expand Down Expand Up @@ -183,7 +183,7 @@ def __init__(self, *args, **kwargs):
self._panelOption = RibbonPanelOptionButton() # type: ignore
self._panelOption.setAutoRaise(True)
self._panelOption.setIcon(QtGui.QIcon(DataFile("icons/linking.png")))
self._panelOption.setIconSize(QtCore.QSize(16, 16))
self._panelOption.setIconSize(QtCore.QSize(self._titleHeight, self._titleHeight))
self._panelOption.setToolTip("Panel options")
self._panelOption.clicked.connect(self.panelOptionClicked) # type: ignore
self._titleLayout.addWidget(self._panelOption, 0)
Expand Down Expand Up @@ -593,3 +593,19 @@ def title(self):
:return: The title.
"""
return self._titleLabel.text()

def setTitleHeight(self, height: int):
"""Set the height of the title widget.
:param height: The height to set.
"""
self._titleHeight = height
self._titleWidget.setFixedHeight(height)
self._panelOption.setIconSize(QtCore.QSize(height, height))

def titleHeight(self) -> int:
"""Get the height of the title widget.
:return: The height of the title widget.
"""
return self._titleHeight
13 changes: 10 additions & 3 deletions pyqtribbon/ribbonbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RibbonBar(QtWidgets.QMenuBar):
_ribbonVisible = True

#: heights of the ribbon elements
_ribbonHeight = 180
_ribbonHeight = 150

#: current tab index
_currentTabIndex = 0
Expand Down Expand Up @@ -250,7 +250,7 @@ def addQuickAccessButton(self, button: QtWidgets.QToolButton):
button.setAutoRaise(True)
self._titleWidget.quickAccessToolBar().addWidget(button)

def setQuickAccessButtonHeight(self, height: int = 30):
def setQuickAccessButtonHeight(self, height: int):
"""Set the height of the quick access buttons.
:param height: The height to set.
Expand All @@ -271,6 +271,13 @@ def setTitle(self, title: str):
"""
self._titleWidget.setTitle(title)

def setTitleWidgetHeight(self, height: int):
"""Set the height of the title widget.
:param height: The height to set.
"""
self._titleWidget.setTitleWidgetHeight(height)

def rightToolBar(self) -> QtWidgets.QToolBar:
"""Return the right toolbar of the ribbon.
Expand All @@ -286,7 +293,7 @@ def addRightToolButton(self, button: QtWidgets.QToolButton):
button.setAutoRaise(True)
self._titleWidget.addRightToolButton(button)

def setRightToolBarHeight(self, height: int = 24):
def setRightToolBarHeight(self, height: int):
"""Set the height of the right buttons.
:param height: The height to set.
Expand Down
24 changes: 15 additions & 9 deletions pyqtribbon/titlewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class RibbonTitleWidget(QtWidgets.QFrame):
_quickAccessButtons = []
_rightToolButtons = []

_quickAccessButtonHeight = 30
_rightButtonHeight = 24
_quickAccessButtonHeight = 20
_rightButtonHeight = 20

# Mouse move events
_start_point = None
Expand Down Expand Up @@ -197,15 +197,14 @@ def addQuickAccessButton(self, button: QtWidgets.QToolButton):
self._quickAccessButtons.append(button)
self._quickAccessToolBar.addWidget(button)

def setQuickAccessButtonHeight(self, height: int = 30):
def setQuickAccessButtonHeight(self, height: int):
"""Set the height of the quick access buttons.
:param height: The height to set.
"""
self._quickAccessButtonHeight = height
self._applicationButton.setIconSize(QtCore.QSize(height, height))
for button in self._quickAccessButtons:
button.setIconSize(QtCore.QSize(height, height))
self._applicationButton.setIcon(self._applicationButton.icon().pixmap(height, height))
self._quickAccessToolBar.setIconSize(QtCore.QSize(height, height))

def title(self) -> str:
"""Return the title of the ribbon.
Expand Down Expand Up @@ -237,14 +236,13 @@ def addRightToolButton(self, button: QtWidgets.QToolButton):
self._rightToolButtons.append(button)
self._rightToolBar.addWidget(button)

def setRightToolBarHeight(self, height: int = 24):
def setRightToolBarHeight(self, height: int):
"""Set the height of the right buttons.
:param height: The height to set.
"""
self._rightButtonHeight = height
for button in self._rightToolButtons:
button.setIconSize(QtCore.QSize(height, height))
self._rightToolBar.setIconSize(QtCore.QSize(height, height))

def helpRibbonButton(self) -> QtWidgets.QToolButton:
"""Return the help ribbon button.
Expand Down Expand Up @@ -282,6 +280,14 @@ def collapseRibbonButton(self) -> QtWidgets.QToolButton:
"""
return self._collapseRibbonButton

def setTitleWidgetHeight(self, height: int):
"""Set the height of the title widget.
:param height: The height to set.
"""
self.setQuickAccessButtonHeight(height)
self.setRightToolBarHeight(height)

def topLevelWidget(self) -> QtWidgets.QWidget:
widget = self
while widget.parentWidget():
Expand Down

0 comments on commit 9afaa74

Please sign in to comment.