D
As you first chose not the simplest task.Try exploring one of the simplest options you can do.
If you have any questions, ask them, try to answer.import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.Qt import *
class Widget(QWidget):
def init(self, parent=None):
super(Widget, self).init(parent)
self.title = QLabel('<h1 style="color: red;">Title Bar</h1>' )
self.title.setAlignment(Qt.AlignCenter)
btn_size = 35
self.btn_close = QPushButton("x")
self.btn_close.setFixedSize(btn_size, btn_size)
self.btn_close.setStyleSheet("background-color: red;")
self.btn_min = QPushButton("_")
self.btn_min.setFixedSize(btn_size, btn_size)
self.btn_min.setStyleSheet("background-color: gray;")
self.btn_max = QPushButton("+")
self.btn_max.setFixedSize(btn_size, btn_size)
self.btn_max.setStyleSheet("background-color: gray;")
self.line = QFrame(self)
self.line.setStyleSheet("border: 3px solid rgb(255, 205, 0);")
self.line.setFrameShape(QtWidgets.QFrame.HLine)
title_bar = QHBoxLayout()
title_bar.setContentsMargins(0, 0, 0, 0)
title_bar.addWidget(self.title)
title_bar.addWidget(self.btn_min)
title_bar.addWidget(self.btn_max)
title_bar.addWidget(self.btn_close)
main_layout = QVBoxLayout(self)
main_layout.setContentsMargins(0, 0, 0, 0)
main_layout.addLayout(title_bar)
main_layout.addWidget(self.line)
main_layout.addStretch()
self.setWindowFlags(Qt.FramelessWindowHint)
class MainWindow(QMainWindow): # QMainWindow -QWidget
def init(self):
super(MainWindow, self).init()
self.centralwidget = QWidget()
self.setCentralWidget(self.centralwidget)
self.widget = Widget(self)
self.widget.btn_close.clicked.connect(self.btn_close_clicked)
self.widget.btn_min.clicked.connect(self.btn_min_clicked)
self.widget.btn_max.clicked.connect(self.btn_max_clicked)
lbl = QLabel('Hello World !!', self, alignment=Qt.AlignHCenter | Qt.AlignTop)
lbl.setStyleSheet("""
QLabel {
font-family: 'Consolas';
color: red;
font-size: 55px;
}
""")
self.setAttribute(Qt.WA_TranslucentBackground, True )
self.setAttribute(Qt.WA_NoSystemBackground, False)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setStyleSheet("""
MainWindow {
background-color: rgba(0, 215, 55, 0);
/* попробуйте заменить строку выше на: v^ <---
background-color: rgba(0, 215, 55, 70);
*/
border: 3px solid rgb(255, 205, 0);
}
""")
self.button = QPushButton("Quit", self)
self.button.setAutoFillBackground(False)
self.button.setStyleSheet("""
background-color: qlineargradient(spread:pad,
x1:0.988818, y1:0.915,
x2:0, y2:0,
stop:0 rgba(53, 129, 90, 255),
stop:1 rgba(255, 255, 255, 255));
font: 75 16pt \"Georgia\";
""")
self.button.setFixedSize(100, 100)
self.button.clicked.connect(self.close)
layout = QVBoxLayout(self.centralwidget)
layout.addWidget(self.widget)
layout.addWidget(lbl)
layout.addStretch()
layout.addWidget(self.button, alignment=Qt.AlignCenter)
def btn_close_clicked(self):
quit()
def btn_min_clicked(self):
self.showMinimized()
def btn_max_clicked(self):
if self.isMaximized():
self.showNormal()
self.widget.btn_max.setText('+')
else:
self.showMaximized()
self.widget.btn_max.setText('R')
def mousePressEvent(self, event):
self.old_Pos = event.globalPos()
self.old_width = self.width()
self.old_height = self.height()
def mouseMoveEvent(self, event):
if (event.buttons() == Qt.LeftButton):
delta = QPoint (event.globalPos() - self.old_Pos)
if (self.old_Pos.x() > self.x() + self.old_width - 10) or \
(self.old_Pos.y() > self.y() + self.old_height - 10):
w = self.old_width+delta.x() if self.old_width+delta.x() > 230 else 230
h = self.old_height+delta.y() if self.old_height+delta.y() > 85 else 85
self.setFixedSize(w, h)
else:
self.move(self.x() + delta.x(), self.y() + delta.y())
self.old_Pos = event.globalPos()
if name == 'main':
app = QApplication(sys.argv)
w = MainWindow()
w.resize(600, 400)
w.show()
sys.exit(app.exec())