-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
main_window.py
75 lines (57 loc) · 2.15 KB
/
main_window.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# coding:utf-8
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QLabel, QMenuBar, QMenu, QStatusBar, QTextEdit, QHBoxLayout
from qframelesswindow import FramelessMainWindow, FramelessDialog
class MainWindow(FramelessMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Frameless Main Window")
# add menu bar
menuBar = QMenuBar(self.titleBar)
menu = QMenu('File(&F)', self)
menu.addAction('open')
menu.addAction('save')
menuBar.addMenu(menu)
menuBar.addAction('Edit(&E)')
menuBar.addAction('Select(&S)')
menuBar.addAction('Help(&H)', self.showHelpDialog)
self.titleBar.layout().insertWidget(0, menuBar, 0, Qt.AlignLeft)
self.titleBar.layout().insertStretch(1, 1)
self.setMenuWidget(self.titleBar)
# add status bar
statusBar = QStatusBar(self)
statusBar.addWidget(QLabel('row 1'))
statusBar.addWidget(QLabel('column 1'))
self.setStatusBar(statusBar)
# set central widget
self.textEdit = QTextEdit()
self.setCentralWidget(self.textEdit)
self.setStyleSheet("""
QMenuBar{background: #F0F0F0; padding: 5px 0}
QTextEdit{border: none; font-size: 15px}
QDialog > QLabel{font-size: 15px}
""")
def showHelpDialog(self):
w = FramelessDialog(self)
# add a label to dialog
w.setLayout(QHBoxLayout())
w.layout().addWidget(QLabel('Frameless Dialog'), 0, Qt.AlignCenter)
# raise title bar
w.titleBar.raise_()
w.resize(300, 300)
# disable resizing dialog
w.setResizeEnabled(False)
w.exec()
if __name__ == '__main__':
# enable dpi scale
QApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
app = QApplication(sys.argv)
# fix issue #50
app.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings)
window = MainWindow()
window.show()
app.exec()