-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4538867
commit d9f8c80
Showing
4 changed files
with
55 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
from PySide6.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout, QMainWindow | ||
from PySide6.QtCore import Qt | ||
|
||
class CustomTitleBar(QWidget): | ||
def __init__(self, parent=None): | ||
super().__init__(parent) | ||
self.layout = QVBoxLayout(self) | ||
self.layout.setContentsMargins(0, 0, 0, 0) | ||
self.title = QLabel("Custom Title", self) | ||
self.title.setStyleSheet("font-weight: bold;") | ||
self.title.setAlignment(Qt.AlignmentFlag.AlignCenter) | ||
self.layout.addWidget(self.title) | ||
import sys | ||
from PySide6.QtWidgets import QApplication, QMainWindow, QMenuBar | ||
import webbrowser | ||
from PySide6.QtGui import QAction | ||
|
||
|
||
class MainWindow(QMainWindow): | ||
def __init__(self): | ||
super().__init__() | ||
self.setWindowTitle("Custom Title Bar") | ||
self.resize(400, 200) | ||
self.setWindowFlags(Qt.WindowType.FramelessWindowHint) | ||
central_widget = QWidget() | ||
self.title_bar = CustomTitleBar(self) | ||
work_space_layout = QVBoxLayout() | ||
work_space_layout.setContentsMargins(11, 11, 11, 11) | ||
work_space_layout.addWidget(QLabel("Hello, World!", self)) | ||
centra_widget_layout = QVBoxLayout() | ||
centra_widget_layout.setContentsMargins(0, 0, 0, 0) | ||
centra_widget_layout.setAlignment(Qt.AlignmentFlag.AlignTop) | ||
centra_widget_layout.addWidget(self.title_bar) | ||
centra_widget_layout.addLayout(work_space_layout) | ||
central_widget.setLayout(centra_widget_layout) | ||
self.setCentralWidget(central_widget) | ||
|
||
if __name__ == "__main__": | ||
app = QApplication([]) | ||
window = MainWindow() | ||
window.show() | ||
app.exec() | ||
self.initUI() | ||
|
||
def initUI(self): | ||
self.menuBar = QMenuBar(self) | ||
self.setMenuBar(self.menuBar) | ||
|
||
# 创建一个菜单 | ||
menu = self.menuBar.addMenu('&文件') | ||
|
||
# 创建一个动作(QAction),并设置其触发时执行的操作 | ||
openWebAction = QAction('打开网页', self) | ||
openWebAction.triggered.connect(self.openWebPage) | ||
|
||
# 将动作添加到菜单中 | ||
menu.addAction(openWebAction) | ||
|
||
def openWebPage(self): | ||
# 使用webbrowser模块打开默认浏览器并导航到指定网址 | ||
webbrowser.open('https://www.example.com') | ||
|
||
|
||
if __name__ == '__main__': | ||
app = QApplication(sys.argv) | ||
mainWin = MainWindow() | ||
mainWin.show() | ||
sys.exit(app.exec()) |