# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QMessageBox, QHBoxLayout, QLabel, QSizePolicy, QDesktopWidget
from PyQt5.QtCore import pyqtSignal, QSize, Qt, QRectF
from PyQt5.QtWidgets import QLineEdit, QTableWidget, QTableWidgetItem, QInputDialog
from PyQt5.QtCore import Qt
from PyQt5 import QtGui
from PyQt5.QtGui import QRegion, QPainterPath
from PyQt5.QtCore import QUrl, QSize
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
class SecondPopup(QWidget):
close_signal = pyqtSignal()
def __init__(self, parent=None):
super(SecondPopup, self).__init__(parent)
self.setWindowFlags(self.windowFlags() & ~ Qt.WindowMinMaxButtonsHint) # 隐藏 最小化和最大化
self.resize(800, 600)
self.setMaximumSize(QSize(800, 600))
self.close_signal.connect(self.closeSlot) # 接收关闭的信号
self.setWindowTitle('DING 应用消息')
# label = QLabel("这是文字~~")
# label.setParent(self)
def handle_click(self, text):
# 1.打开网址
self.browser = QWebEngineView()
self.browser.load(QUrl('https://www.baidu.com'))
self.browser.page().fullScreenRequested.connect(self._fullScreenRequested)
layout = QVBoxLayout() # 垂直布局
layout.addWidget(self.browser)
self.setLayout(layout)
self.show()
# 2.展示图片和内容
# layout = QVBoxLayout() # 垂直布局
# l1 = QLabel()
# png = QtGui.QPixmap(r'C:\Users\administered\Desktop\报表中心1\180109DwjiorlsEOFZ37wM.png')
# l1.setPixmap(png)
# l1.setAlignment(Qt.AlignCenter) # 居中
#
# label = QLabel(self) # QLabel标签展示文本
# # label.setParent(self)
# label.setWordWrap(True)
# label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
# label.setText(text)
# # label.setText('D:\projectgame\Python38\python.exe C:/Users/administered/Desktop/files/qt_file/temp/dialog_widget.py hello world!')
# # label.setObjectName('label')
# # label.setAlignment(Qt.AlignBottom | Qt.AlignRight) # 设置标签位置
# label.setAlignment(Qt.AlignCenter) # 设置标签位置
# # label.move(50, 60)
#
# layout.addWidget(l1)
# layout.addWidget(label)
# layout.addStretch(0) # 空间占用一行或者一列,用于界面像田字格一样平分
# self.setLayout(layout)
# if not self.isVisible(): #第二个窗口处于隐藏状态时进行展示
# self.show()
def _fullScreenRequested(self, request):
request.accept()
self.browser.showFullScreen()
def closeEvent(self, event):
self.close_signal.emit()
def closeSlot(self):
self.close()
class FirstPopup(QWidget):
close_signal = pyqtSignal()
def __init__(self, parent=None):
super(FirstPopup, self).__init__(parent)
# 不显示最小化,最大化 和关闭按钮
self.setWindowFlags(self.windowFlags() &~ Qt.WindowCloseButtonHint &~ Qt.WindowMinMaxButtonsHint)
self.setWindowTitle('DING 应用消息')
self.width, self.height = 360, 110
self.setFixedSize(self.width, self.height)
# 显示圆角
rect = QRectF(0, 0, self.width, self.height)
path = QPainterPath()
path.addRoundedRect(rect, 5, 5)
polygon = path.toFillPolygon().toPolygon()
self.setMask(QRegion(polygon))
ylayout = QHBoxLayout() # 水平布局
ylayout.addStretch(0)
ylayout.addStretch(0)
self.button = QPushButton(self)
self.button.setText('查看详情')
self.button.setFixedWidth(80)
self.button.setFixedHeight(35)
# self.button.clicked.connect(self.show_details)
self.button.move(250, 50)
self.two = SecondPopup()
text = 'D:\projectgame\Python38\python.exe C:/Users/administered/Desktop/files/qt_file/temp/dialog_widget.py hello world!'
self.button.clicked.connect(lambda: self.two.handle_click(text))
self.close_signal.connect(self.closeSlot)
# self.two.close_signal.connect(self.closeSlot) # 通过关闭子窗口关闭上一级窗口
ylayout.addWidget(self.button)
ylayout.addStretch(0)
xlayout = QVBoxLayout() # 垂直布局
# xlayout.addStretch(0)
label = QLabel(self)
label.setWordWrap(True)
label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
label.setText('hello world:')
label.setAlignment(Qt.AlignLeft)
xlayout.addWidget(label)
xlayout.addStretch(0)
xlayout.addLayout(ylayout)
xlayout.addStretch(0)
self.setLayout(xlayout)
cp = QDesktopWidget().availableGeometry().bottomRight()
# size = QDesktopWidget().availableGeometry().size()
self.move(cp.x()-self.width-15, cp.y()-self.height-40) # 设置窗口在屏幕中的位置,在右下角
def closeEvent(self, event):
self.close_signal.emit()
def closeSlot(self):
self.two.close()
self.close()
def show_details(self):
# reply = QMessageBox.information(self, '详情标题', '这是弹窗的详情信息', QMessageBox.Ok)
qw = QInputDialog.getText(self, 'title', 'my text')
if __name__ == '__main__':
app = QApplication(sys.argv)
popup = FirstPopup()
popup.show()
sys.exit(app.exec_())
pyqt5 QWidget 弹窗消息
于 2024-02-03 14:04:08 首次发布