-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool_bar.py
25 lines (20 loc) · 861 Bytes
/
tool_bar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class ToolBar(QToolBar):
def __init__(self, title):
super(ToolBar, self).__init__(title)
self.layout().setSpacing(0)
self.layout().setContentsMargins(0, 0, 0, 0)
self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
def addAction(self, action):
if isinstance(action, QWidgetAction):
return super(ToolBar, self).addAction(action)
button = QToolButton()
button.setDefaultAction(action)
button.setToolButtonStyle(self.toolButtonStyle())
self.addWidget(button)
# center align
for i in range(self.layout().count()):
if isinstance(self.layout().itemAt(i).widget(), QToolButton):
self.layout().itemAt(i).setAlignment(Qt.AlignCenter)