提交 4fad8510 编写于 作者: L LaraStuStu

Create tool_bar.py

上级 99212056
from qtpy import QtCore
from qtpy import QtWidgets
class ToolBar(QtWidgets.QToolBar):
def __init__(self, title):
super(ToolBar, self).__init__(title)
layout = self.layout()
m = (0, 0, 0, 0)
layout.setSpacing(0)
layout.setContentsMargins(*m)
self.setContentsMargins(*m)
self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
def addAction(self, action):
if isinstance(action, QtWidgets.QWidgetAction):
return super(ToolBar, self).addAction(action)
btn = ToolButton()
btn.setDefaultAction(action)
btn.setToolButtonStyle(self.toolButtonStyle())
self.addWidget(btn)
class ToolButton(QtWidgets.QToolButton):
"""ToolBar companion class which ensures all buttons have the same size."""
minSize = (60, 60)
def minimumSizeHint(self):
ms = super(ToolButton, self).minimumSizeHint()
w1, h1 = ms.width(), ms.height()
w2, h2 = self.minSize
self.minSize = max(w1, w2), max(h1, h2)
return QtCore.QSize(*self.minSize)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册